Created
May 4, 2011 22:46
-
-
Save aseemk/956205 to your computer and use it in GitHub Desktop.
Streamline properly maintains `this` before and after async calls... <3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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