var pet={
    word:'...',
    speak:function(say){
        console.log(say+' '+this.word)
    }
}
//pet.speak('speak')//speak ...
var dog={
    word:'wang'
}
//改变this到dog上
pet.speak.call(dog,'speak')//spaeck wang
function pet1(word){
    this.word=word;
    this.speak=function(){
        console.log(this.word)
    }
}
//类似继承
function dog1(word){ pet1.call(this,word); //pet1.apply(this,arguments) } var dog1=new dog1('wang') dog1.speak()//wang

 

posted on 2018-07-04 17:18  chenlw101  阅读(126)  评论(0编辑  收藏  举报