Skip to content

Instantly share code, notes, and snippets.

@ralt
Last active December 17, 2015 05:59
Show Gist options
  • Save ralt/5561744 to your computer and use it in GitHub Desktop.
Save ralt/5561744 to your computer and use it in GitHub Desktop.
Example of bind usage
var obj = {
clickHandler: function() {
console.log(this); // "el"
}
};
el.addEventListener('click', obj.clickHandler.bind(el));
// Without "bind", we need something like this:
var obj = {
clickHandler: function() {
var that = this;
return function() {
console.log(that);
};
}
};
el.addEventListener('click', obj.clickHandler.call(el));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment