當(dāng)前位置:
首頁(yè) >
前端技术
> javascript
>内容正文
javascript
javascript 函数和对象 再顺一顺
生活随笔
收集整理的這篇文章主要介紹了
javascript 函数和对象 再顺一顺
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
在javascript 中 函數(shù)也是對(duì)象 ,當(dāng)然對(duì)象更是對(duì)象,是復(fù)雜類型,對(duì)于初學(xué)者或者自學(xué)者 總有一種變來(lái)變?nèi)サ母杏X 別的不說(shuō)了看碼
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title></title> </head> <script>var ob={ //創(chuàng)建一個(gè)對(duì)象age:10,name:"sdfsdf",show:function(){document.writeln(this.age+" "+this.name);}}var bb=function(){}//創(chuàng)建一個(gè)函數(shù)bb.names="admin";//吧函數(shù)當(dāng)成一個(gè)對(duì)象 添加屬性和方法bb.age=30;bb.show=function(){document.writeln(this.names+" "+this.age);};var fn=function(name,psw){ //有參數(shù)的函數(shù)this.name=name;this.psw=psw;this.show=function(){document.writeln(this.name+" "+this.psw);}}var t=new fn(25,"admin");fn.prototype.run=function() //對(duì)fn 函數(shù)再添加一個(gè)方法{document.writeln(this.name+" "+this.psw);}</script> <body><input type="button" value="object" οnclick="ob.show()"> <input type="button" value="function->object" οnclick="bb.show()"> <input type="button" value="function" οnclick="t.show()"> <input type="button" value="function prototype" οnclick="t.run()"> </body> </html>
總結(jié)
以上是生活随笔為你收集整理的javascript 函数和对象 再顺一顺的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 学javascript 必须了解 typ
- 下一篇: Spring中ApplicationCo