Closure - Lexical scope

with this as binding

by Rich Costello

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?