Closure - Lexical scope
with this as binding
JavaScript
var obj = {
count: 0,
cool: function coolFn() {
if (this.count < 1) {
setTimeout(function timer(){
this.count++;
console.log("more awesome");
}.bind(this), 100); //bind this sets this for setTimeout
}
}
};
obj.cool(); // awesome?