The amazing yield*

Ibrahim Tanyalcin
1 min readDec 12, 2017

--

truly amazing

I do not radically defend old school specs when it comes to javascript. Change that comes from authentic need (as opposed to bandwagon’s hierarchy of needs) is good, period.

On the other hand, especially at our times when new specs are implicitly && indirectly && politely shoveled down the throat of devs, I retain the right to remain skeptical. When I see words like powerful and convenient at the spec’s page or sense passive mudslinging to older/custom implementations, I retain the right to remain extra skeptical.

Today, out of nowhere with pure randomness, I opened the console and wrote this:

function* f (){
var i = 0;
while(true) {
yield ++i;
}
}

Seems great. Then I did this:

var gen = f(),
x = gen.next(),
y = gen.next();
console.log(x === y); //false

So every time we call next , seems like we get a brand new object.

Now that’s truly amazing!

--

--

Ibrahim Tanyalcin

Postdoc in Bioinformatics. Former genetic engineer. All time geometry enthusiast. Interested in Viz. Works? mutaframe.com, i-pv.org, ibrahimtanyalcin.com/gwent