手写bind
<script>
Function.prototype.myBind = function (thisArg, ...args) {
// 返回一个绑定了this的新函数
return (...args2) => this.call(thisArg, ...args, ...args2)
}
const person = {
name: 'mandy',
age: 21
}
function fun(numA, numB, numX, numY) {
console.log(this);
console.log(numA, numB, numX, numY);
return numA + numB + numX + numY;
}
const funBind = fun.myBind(person, 1, 2)
const result2 = funBind(3, 4)
console.log('bind - result:' + result2);
</script>
.
.
.
.
.
.