Skip to content

Instantly share code, notes, and snippets.

@mopig
Created June 11, 2014 08:24
Show Gist options
  • Save mopig/ba7fe3aef182e083806e to your computer and use it in GitHub Desktop.
Save mopig/ba7fe3aef182e083806e to your computer and use it in GitHub Desktop.
function MyObject(element) {
this.elm = element;
element.addEventListener('click', this.onClick.bind(this), false);
};
MyObject.prototype.onClick = function(e) {
var t=this; //do something with [t]...
//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