const wandou = {
age: 27,
printAge: function (value) {
return this.age;
}
}
const printAge = wandou.printAge;
console.log(printAge()) //undefined
const bindPrintAge = printAge.bind(wandou)
console.log(bindPrintAge()) //27
console.log("-----------------split line")
Function.prototype.bind1 = function () {
const func = this
const obj = Array.prototype.shift.call(arguments);
const param = Array.prototype.slice.call(arguments);
return function () {
// apply 数组
func.apply(obj, Array.prototype.concat.call(param,Array.prototype.slice.call(arguments)))
// call 分别接受参数
}
}
const bindPrintAge1 = wandou.printAge.bind1(wandou)
console.log(bindPrintAge1()) //27
console