Skip to content

Instantly share code, notes, and snippets.

@aseemk
Created May 4, 2011 22:46
Show Gist options
  • Save aseemk/956205 to your computer and use it in GitHub Desktop.
Save aseemk/956205 to your computer and use it in GitHub Desktop.
Streamline properly maintains `this` before and after async calls... <3
function Animal(name) {
this.name = name;
}
Animal.prototype.drink = function (_) {
console.log(this.name + " is about to grab a drink at the watering hole...");
// simulate async step:
setTimeout(_, 1000);
console.log(this.name + " finished drinking.");
};
var cheetah = new Animal('Bob the Cheetah');
cheetah.drink(_);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment