var obj ={ id:"awesome",cool:functioncoolFn(){console.log( this.id );}};var id ="not awesome";obj.cool();// awesomesetTimeout( obj.cool,100 );// not awesome
var obj = {
count: 0,
cool: function coolFn() {
if (this.count < 1) {
setTimeout( function timer(){
this.count++; // `this` is safe because of `bind(..)`
console.log( "more awesome" );
}.bind( this ), 100 ); // look, `bind()`!
}
}
};
obj.cool(); // more awesome