手写bind

16 阅读1分钟
  function print(record){
     console.log(this.name, record)
  }
  
  Object.prototype.mynewbind = function(targetobj, ...args){  // revise Object.prototype
     targetobj.newprintmethod=this // this = print function{...}
     return function(...args){
        targetobj.newprintmethod(...args)
     }
  }
  
  print.mynewbind({name:John},'hello hello')