Open Davidyanlong opened 5 years ago
Function.prototype.mybind = function(context, ...args) { let fun = this; function bound(...args2) { //如题,这句话不理解是什么意思?什么情况下 this instanceof bound ==true let self = this instanceof bound ? this : context; return fun.apply(self, args.concat(args2)); } bound.prototype = Object.create(fun.prototype); return bound; };
function Test(){ } let bindTest = Test.bind({}); let a = new bindTest() //此时 this instanceof bound 是true。