bind: 改变this的指向,返回一个新函数(它不会立即执行,需要调用新函数才能执行;apply call方法是立即执行)
let obj = {
name: 'jason888'
}
function fun(name,age){
//console.log(888);
//console.log("this:",this);
console.log("this.name:",this.name);
// console.log("arguments:",arguments.callee);
// console.log("Array:",Array.prototype);
// console.log(name);
// console.log(age);
}
//let foo = fun.bind(obj,'meay',33);
//foo();
//bind: 改变this指向,返回一个新函数
Function.prototype.bind2 = function(context){
let self = this;
return function(){
self.apply(context,Array.prototype.slice.call(arguments,1))
}
}
let foo = fun.bind2(obj,'meay',33);
foo();