Skip to content

Instantly share code, notes, and snippets.

@christophercliff
Created September 19, 2013 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christophercliff/6626134 to your computer and use it in GitHub Desktop.
Save christophercliff/6626134 to your computer and use it in GitHub Desktop.
Function.prototype.bind vs fn(callback, ctx)
this.myMethod(callback.bind(this))
// vs.
this.myMethod(callback, this)
// In the former, context is in the hands of the user. In the latter, the context is the responsibility of the owner of `myMethod`. Every method in that API that accepts a callback now requires a bunch of boilerplate, e.g.:
myMethod: function (callback, ctx) {
ctx = (ctx || null)
// do stuff...
return callback.apply(ctx, args)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment