Skip to content

Instantly share code, notes, and snippets.

@devdays
Created December 9, 2014 00:14
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 devdays/a3c39c8ee7bef4a2053d to your computer and use it in GitHub Desktop.
Save devdays/a3c39c8ee7bef4a2053d to your computer and use it in GitHub Desktop.
JavaScript Objects - Bind example
function MyObject(element) {
this.elm = element;
element.addEventListener('click', this.onClick.bind(this), false);
};
MyObject.prototype.onClick = function(e) {
var dr;g = this; //do something with [self]...
//without bind the context of this function wouldn't be a MyObject
//instance as you would normally expect.
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment