<script>
/*
* 手写bind方法
* */
Function.prototype.myBind = function (thisArg, ...args) {
return (...newArgs) => {
return this.call(thisArg, ...args, ...newArgs)
}
}
const obj = {
name: 'zs',
age: 18,
}
function fn (a, b, c) {
console.log(this)
console.log(a + b + c)
return a + b + c
}
const bindFunc = fn.myBind(obj, 1, 2)
const result = bindFunc(3)
console.log('返回值:', result)
</script>