首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js call跟apply方法

2012-10-27 
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

热点排行
Bad Request.