//bind
Function.prototype.bind1 = function(){
  let args = Array.prototype.slice.call(arguments);
  let t = args.shift();
  let self = this;
  return function(){
        return self.apply(t,agrs);
    }        
}
//call
 Function.prototype.call1 = function(t,...args){
       let self = this;
       return (function(){
           return self.apply(t,args);
       })()
    }
//apply
 Function.prototype.apply1 = function (t,args) {
        let self = this;
        return (function(){
            console.log(...args)
            return self.call(t,...args); 
        })()
    }
//调用

  function fn1(a, b) {
            console.log(this)
            console.log(a, b)
            return `this is fn1`
    
    }
    // const fn2 = fn1.bind({x:100},10,20)
    // fn2();
    // const fn2 = fn1.apply1({x:100},[19,20])
    
    const fn3 = fn1.call1({x:100},19,30)

 

posted on 2020-03-21 14:54  chenlw101  阅读(304)  评论(0编辑  收藏  举报