javascript中apply()和call()方法的区别:
function.call(this, arg1,arg2,arg3) == function.apply(this, arguments)==this.foo(arg1, arg2, arg3)
call, apply都属于Function.prototype的一个方法,它是JavaScript引擎内在实现的,因为属于Function.prototype,所以每个Function对象实例,也就是每个方法都有call, apply属性.既然作为方法的属性,那它们的使用就当然是针对方法的了.这两个方法是容易混淆的,因为它们的作用一样,只是使用方式不同.
参考:
http://msdn.microsoft.com/en-us/library/ie/4zc42wh1(v=vs.94).aspx
http://msdn.microsoft.com/en-us/library/ie/h2ak8h2y(v=vs.94).aspx
http://www.cnblogs.com/fighting_cp/archive/2010/09/20/1831844.html
寄生组合继承(Parasitic Combination Inheritance):
function SuperType(name){ this.name = name; this.colors = ["red", "blue", "green"]; }; SuperType.prototype.sayName = function(){ alert(this.name); }; function SubType(name, age){ SuperType.call(this, name); this.age = age; } SubType.prototype = new SuperType(); SubType.prototype.constructor = SubType; SubType.prototype.classname = "SubType"; SubTYpe.prototype.sayAge = function(){ alert(this.age); };