-
-
Save rwaldron/6872339 to your computer and use it in GitHub Desktop.
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
var a = [ | |
{ | |
// Look, ma, no `this` | |
foo: function foo() { | |
setTimeout(foo,100); | |
console.log("foo"); | |
} | |
} | |
]; | |
var b = [ | |
{ | |
// shorthand method syntax is nice, but introduces `this` issues | |
// because of lack of lexical name binding | |
foo() { | |
setTimeout(this.foo,100); // ** uglier this.foo | |
console.log("foo"); | |
} | |
} | |
]; |
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
var a = [ | |
{ | |
// Look, ma, no `this` | |
foo: function foo(count) { | |
if (count < 10) { | |
setTimeout(function bar(){ | |
if (count % 2 === 0) { | |
count++; | |
setTimeout(bar,100); | |
} | |
else { | |
foo(count+2); | |
} | |
},100); | |
} | |
else { | |
console.log("foo: " + count); | |
} | |
} | |
} | |
]; | |
var b = [ | |
{ | |
foo(count) { | |
if (count < 10) { | |
let bar = _ => { | |
if (count % 2 === 0) { | |
count++; | |
setTimeout(bar,100); | |
} | |
else { | |
this.foo(count+2); | |
} | |
}; | |
setTimeout(bar,100); | |
} | |
else { | |
console.log("foo: " + count); | |
} | |
} | |
} | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://gul.ly/dhj
Options -> Show All Options -> blockBinding