Skip to content

Instantly share code, notes, and snippets.

@seanmonstar
Created October 29, 2011 00:03
Show Gist options
  • Save seanmonstar/1323877 to your computer and use it in GitHub Desktop.
Save seanmonstar/1323877 to your computer and use it in GitHub Desktop.
If you use `var self = this`, die.
var Example = new Class({
initialize: function() {
// i now hate you if you do this in my codez
var self = this; // or that.
// 10 or 20 lines down, in another closure, I have to read up to
// make sure `self` is set the `this` that I want
// instead, this is they way to go
var example = this;
// i know what `example` is, because we're in the Example class
myEl.addEvent('click', function() {
example.derp();
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment