js call跟apply方法

js call和apply方法call()方法call(obj,arg1,arg2...)call()方法第一个参数是用作this的对象,其他参数直

js call和apply方法

call()方法
call(obj,arg1,arg2...);
call()方法第一个参数是用作this的对象,其他参数直接传递给对象函数本身

例如:

function Cat(cColor){   this.color=cColor;   this.showColor=function(){      alert(this.color);    }}function TomCat(cColor){    Cat.apply(this,arguments);} var tom=new TomCat("black");  tom.showColor();

1 楼 chunchong 2011-10-18   貌似有点不大对
方法第一个参数是用作this的对象????? 2 楼 xixian 2011-10-18   chunchong 写道貌似有点不大对
方法第一个参数是用作this的对象?????

个人理解就是子类的对象

可参考w3school资料
http://www.w3school.com.cn/js/pro_js_inheritance_implementing.asp