改版this指向

call apply bind 改版this指向

//var name ='jary';

//var a ={

     name:'Tom',

say:function(){

console.log(this,name);

}

}

var f =a,say;

var obj={

name:'zhangsan',

say:function(str,str2){

conslole.log(this.name+ ' '+str+' ' +str2)

  // obj.say.call({name:'宁宁'});

    obj.say.call({name:'宁宁'},'hello','world');

    obj.say.apply({name:'宁宁'},'hello','world');

    var f = obj.bind({name:'宁宁'})

你可能感兴趣的:(改版this指向)