Skip to content

Instantly share code, notes, and snippets.

@hoorayimhelping
Created February 15, 2013 09:22
Show Gist options
  • Save hoorayimhelping/4959334 to your computer and use it in GitHub Desktop.
Save hoorayimhelping/4959334 to your computer and use it in GitHub Desktop.
Replace context binding to a variable with built in function
Person.prototype.save = function() {
var person = this;
person.database.insert(person.properties, function(err, result) {
person.properties = result;
});
};
// becomes:
Person.prototype.save = function() {
person.database.insert(person.properties, $.proxy(function(err, result) {
this.properties = result;
}, this));
};
window.location = www.youtube.com/watch?v=F4jBuKY7jb8 //BOOM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment