Created
January 18, 2017 08:16
-
-
Save DimitryDushkin/7b29de6039c97d7c597703b1b11660f0 to your computer and use it in GitHub Desktop.
Power or let (JS)
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 letExample() { | |
var a = [1,2,3,4,5], | |
seq = Promise.resolve(); | |
for (let b of a) { | |
seq = seq.then(() => new Promise(resolve => { setTimeout(()=> {console.log(b); resolve();}, 100) })); | |
} | |
} | |
function varExample() { | |
var a = [1,2,3,4,5], | |
seq = Promise.resolve(); | |
for (var b of a) { | |
seq = seq.then(() => new Promise(resolve => { setTimeout(()=> {console.log(b); resolve();}, 100) })); | |
} | |
//5, 5, 5, 5, 5 | |
} | |
letExample(); // -> 1, 2, 3, 4, 5 | |
setTimeout(varExample, 1000); // -> 5, 5, 5, 5, 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment