Skip to content

Instantly share code, notes, and snippets.

@matthewstokeley
Last active June 8, 2019 19:51
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 matthewstokeley/e3726859da60c6556975913d28cf77d6 to your computer and use it in GitHub Desktop.
Save matthewstokeley/e3726859da60c6556975913d28cf77d6 to your computer and use it in GitHub Desktop.

Javascipt Context Binding

.bind() is a powerful method for changing or preserving the context and therefore the scope available to an expression.

It can be used to preserve contexts for callbacks that will be invoked and executed in different block scopes, for instance in this closure

const fn = function(fn, ...args) {
  return fn.call(this, ...args)
}.bind(this)


 
let func = callback(fn);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment