JS 面向对象、prototype、call()、apply() 收藏 一、 起因 那天用到 prototype
js 于是打开看看,才看几行就满头雾水,原因是对js 的面向对象不是很熟悉,于是百度+google 了一把,最后终于算小有收获,写此纪念一下^_^
prototype
js 代码片段 view plaincopy to clipboardprint
var Class = { create: function() { return function() { this
initialize
apply(this , arguments); } } } var Class = { create: function() { return function() { this
initialize
apply(this , arguments); } } } // Class 使用方法如下 view plaincopy to clipboardprint
var A = Class
create(); A
prototype={ initialize:function(v){ this
value=v; } showValue:function(){ alert(this
value); } } var a = new A(‘helloWord
showValue();//弹出对话框 helloWord
var A = Class
create(); A
prototype={ initialize:function(v){ this
value=v; } showValue:function(){ alert(this
value); } } var a = new A(‘helloWord
showValue();//弹出对