标签:alert name edit 输入 不能 对象 动态改变 var get
javascript中面向对像的能力是后来加进来的, 为了兼容性, 所以整出了很多奇特的东西,
function Animal(){ this.name = "Animal"; this.showName = function(){ alert(this.name); } } function Cat(){ this.name = "Cat"; } var animal = new Animal(); var cat = new Cat(); //通过call或apply方法,将原本属于Animal对象的showName()方法交给对象cat来使用了。 //输入结果为"Cat" animal.showName.call(cat,","); //animal.showName.apply(cat,[]);
所以,可以看出call和apply是为了动态改变this而出现的,当一个object没有某个方法,但是其他的有,我们可以借助call或apply用其它对象的方法来操作。
标签:alert name edit 输入 不能 对象 动态改变 var get
原文地址:http://www.cnblogs.com/answercard/p/6080065.html