turtle-rock icon indicating copy to clipboard operation
turtle-rock copied to clipboard

实现 function 的 bind 函数中,求教instanceof这句是什么意思?

Open Davidyanlong opened this issue 5 years ago • 1 comments

     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;
       };

Davidyanlong avatar Oct 20 '19 15:10 Davidyanlong

function Test(){
}
let bindTest = Test.bind({});
let a = new bindTest() //此时 this instanceof bound 是true。

scofieldfan avatar Oct 23 '19 03:10 scofieldfan