turtle-rock
turtle-rock copied to clipboard
实现 function 的 bind 函数中,求教instanceof这句是什么意思?
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。