基本的函数绑定bind方法

function bind(fn, context) {
  return function() {
    return fn.apply(context, arguments)
  }
}

var greet = function(greeting, punctuation) {
  return greeting + " " + this.user + punctuation
}
var object = { user: "wangdanting" }

var bound = bind(greet, object)

bound("hi", "!")
// => "hi wangdanting!"

 

你可能感兴趣的:(lodash)