call,apply和bind的用法及区别
例1
1 var name = ‘小王‘, age = 17 2 var obj = { 3 name: ‘小张‘, 4 objAge: this.age, 5 myFun: function() { 6 console.log(this.name + ‘年龄:‘ + this.age); 7 } 8 } 9 10 console.log(obj.objAge); //17 11 obj.myFun() // 小张年龄:undefined
1 var name = ‘小王‘, age = 17 2 var obj = { 3 name: ‘小张‘, 4 objAge: this.age, 5 myFun: function() { 6 console.log(this.name + ‘年龄:‘ + this.age); 7 } 8 } 9 10 console.log(obj.objAge); //17 11 obj.myFun() // 小张年龄:undefined