Function.prototype.myBind = function (thisArg, ...args) {
var self = this
console.log(self)
// new优先级
var fbound = function (...innerArg) {
self.apply(this instanceof self ? this : thisArg, args.concat(innerArg))
}
// 继承原型上的属性和方法
console.log(self.prototype)
fbound.prototype = Object.create(self.prototype);
return fbound;
}
const obj = { name: '写代码像蔡徐抻' }
function foo() {
console.log(this)
console.log([...arguments])
}
foo.prototype.aaa = 1
foo.myBind(obj, 'a', 'b', 'c')(1) //输出写代码像蔡徐抻 ['a', 'b', 'c'