call和apply的用法。

//实现一个继承父类构造函数

function Super(name){
    this.name=name;
    this.showName = function(){
        console.log(this.name);
   }
}

function Sub(name){
    Super.call(this,name);
   //Super.apply(this,arguments);
}

var s = new Sub("superboo");
s.showName();

猜你喜欢

转载自bingsizi.iteye.com/blog/2285762