當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
javascript 函数和对象 再顺一顺
生活随笔
收集整理的這篇文章主要介紹了
javascript 函数和对象 再顺一顺
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在javascript 中 函數也是對象 ,當然對象更是對象,是復雜類型,對于初學者或者自學者 總有一種變來變去的感覺 別的不說了看碼
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title></title> </head> <script>var ob={ //創建一個對象age:10,name:"sdfsdf",show:function(){document.writeln(this.age+" "+this.name);}}var bb=function(){}//創建一個函數bb.names="admin";//吧函數當成一個對象 添加屬性和方法bb.age=30;bb.show=function(){document.writeln(this.names+" "+this.age);};var fn=function(name,psw){ //有參數的函數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() //對fn 函數再添加一個方法{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>
總結
以上是生活随笔為你收集整理的javascript 函数和对象 再顺一顺的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 学javascript 必须了解 typ
- 下一篇: 技术人员如何创业《四》- 打造超强执行力