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
//output | |
repl: Line 30: Direct super call is illegal in non-constructor, use super.doWork() instead | |
28 | | |
29 | doWork() { | |
> 30 | let person = super(); | |
| ^ | |
31 | return `${person} paid`; | |
32 | } | |
33 | } |
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
// output | |
10 | |
// generated code | |
"use strict"; | |
var numbers = regeneratorRuntime.mark(function callee$0$0(start, end) { | |
var i; | |
return regeneratorRuntime.wrap(function callee$0$0$(context$1$0) { | |
while (1) switch (context$1$0.prev = context$1$0.next) { |
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
let s = new Set([1,2,3]); | |
s.add("foo"); | |
console.log(s.size); |
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
let pr1 = new Promise( (resolve, reject) => { | |
resolve(1); | |
}); | |
// ignored value. | |
// would have been nice of function is required to have correct arguments | |
// TODO: try with JSHint | |
pr1.then( () => { | |
console.log("hello"); | |
}) |
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 flag = false; | |
var promise = Promise.resolve(); | |
// not linear execution of code! | |
// is the then callback pushed onto the call-stack. how ? | |
promise.then( (x) => { | |
console.log(`flag is ${flag}`); // flag is true | |
}) | |
flag = true |
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 getStockPrice() { | |
seq.throw('oops! could not get stock price'); | |
// seq.next(80); | |
} | |
function executeTrade() { | |
setTimeout(function() { | |
console.log("trade done"); | |
seq.next(true); | |
}, 300); |
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
works if generator is not calling another function ? | |
example from http://davidwalsh.name/es6-generators-dive | |
similar example at https://gist.github.com/deepak/9a7337d7a641f8af9c8b |
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
let price = 10; | |
let stockPrice = function () { | |
// iterator.next(price++); // throws a "Generator is already running" error | |
return price++ | |
} | |
let oops = function () { | |
throw new Error("oops!"); | |
} |
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
let price = 10; | |
let stockPrice = function () { | |
setTimeout(function() { | |
iterator.next(price++); | |
console.log(price); //=> 10 | |
// why is this logged ? next does not behave like return ? | |
// and it is always 10. "price++" did not increment value of price | |
}, 300); | |
} |
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
let price = 10; | |
let stockPrice = function () { | |
setTimeout(function() { | |
iterator.next(price++); | |
}, 300); | |
} | |
let errorInStockPrice = function() { | |
setTimeout(function() { |