Skip to content

Instantly share code, notes, and snippets.

@cjohansen
Created September 2, 2010 10:50
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 cjohansen/562151 to your computer and use it in GitHub Desktop.
Save cjohansen/562151 to your computer and use it in GitHub Desktop.
// Requires Function.prototype.bind
(function () {
var chr = {
name: "Christian"
sleepAndGreet: function (callback) {
setTimeout(function () {
callback("Hi, I'm " + this.name);
}.bind(this), 2000);
}
};
chr.sleepAndGreet(function (greeting) {
alert(greeting);
});
chr.name = "Chris Joh";
// Alerts "Hi, I'm Chris Joh"
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment