Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

function*

7 views
Skip to first unread message

Amit Zur

unread,
Jun 19, 2015, 11:11:21 AM6/19/15
to mozilla-dev-d...@lists.mozilla.org
Hi,
I'm running through the devtools source and see a lot of function declarations like this:
function*() {...}

Can you tell me what this syntax is all about?

Nicolas B. Pierron

unread,
Jun 19, 2015, 11:18:25 AM6/19/15
to mozilla-dev-d...@lists.mozilla.org
These functions are generators [1][2]. To make it simple, you can interupt
them and resume them on yield statements. Which is quite useful when
combined with for-of loops.

[1] https://hacks.mozilla.org/2015/05/es6-in-depth-generators/
[2]
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*

--
Nicolas B. Pierron

Dan Callahan

unread,
Jun 19, 2015, 11:19:18 AM6/19/15
to Amit Zur, mozilla-dev-d...@lists.mozilla.org
Those are generator functions, which were (finally!) standardized in ES6 /
ES2015.

David Walsh has a good intro at http://davidwalsh.name/es6-generators, and
Jason Orendorff wrote about them on Hacks last month:
https://hacks.mozilla.org/2015/05/es6-in-depth-generators/

On Fri, Jun 19, 2015 at 10:03 AM, Amit Zur <sendwi...@gmail.com> wrote:

> Hi,
> I'm running through the devtools source and see a lot of function
> declarations like this:
> function*() {...}
>
> Can you tell me what this syntax is all about?
> _______________________________________________
> dev-developer-tools mailing list
> dev-devel...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-developer-tools
>

Victor Porof

unread,
Jun 19, 2015, 11:20:39 AM6/19/15
to Amit Zur, mozilla-dev-d...@lists.mozilla.org
Generators! [0]

Most often used with Task [1], at least until async/await land in ES7.

[0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*
[1] http://taskjs.org/
0 new messages