<script type='text/javascript'>
function foo(name, age, sex) {
console.log(this, name, age, sex)
}
/* let newFoo = foo.bind("123", "张三", 20)
newFoo("男") */
Function.prototype.edBind = function (thisArg, ...arg) {
thisArg = (thisArg === null || thisArg === undefined) ? window : Object(thisArg)
Object.defineProperty(thisArg, "fn", {
configurable: true,
value: this
})
return function (...newArg) {
thisArg.fn(...arg, ...newArg)
}
}
let newFoo = foo.edBind("123", "张三", 20)
newFoo("男")
</script>