Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7604715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:59:04+00:00 2026-05-30T23:59:04+00:00

In this page I found a new JavaScript function type: // NOTE: function* is

  • 0

In this page I found a new JavaScript function type:

// NOTE: "function*" is not supported yet in Firefox.
// Remove the asterisk in order for this code to work in Firefox 13 

function* fibonacci() { // !!! this is the interesting line !!!
    let [prev, curr] = [0, 1];
    for (;;) {
        [prev, curr] = [curr, prev + curr];
        yield curr;
    }
}

I already know what yield, let and [?,?]=[?,?] do, but have no idea what the function* is meant to be. What is it?

P.S. don’t bother trying Google, it’s impossible to search for expressions with asterisks (they’re used as placeholders).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:59:06+00:00Added an answer on May 30, 2026 at 11:59 pm

    It’s a Generator function.

    Generators are functions which can be exited and later re-entered. Their context (variable bindings) will be saved across re-entrances.

    Calling a generator function does not execute its body immediately; an iterator object for the function is returned instead. When the iterator’s next() method is called, the generator function’s body is executed until the first yield expression, which specifies the value to be returned from the iterator or, with yield*, delegates to another generator function.


    Historical note:

    It’s a proposed syntax for EcmaScript.next.

    Dave Herman of Mozilla gave a talk about EcmaScript.next. At 30:15 he talks about generators.

    Earlier, he explains how Mozilla is experimentally implementing proposed language changes to help steer the committee. Dave works closely with Brendan Eich, Mozilla’s CTO (I think), and the original JavaScript designer.

    You can find more detail on the EcmaScript working group wiki: http://wiki.ecmascript.org/doku.php?id=harmony:generators

    The working group (TC-39) has general agreement that EcmaScript.next should have some kind of generator iterator proposal, but this is not final.

    You shouldn’t rely on this showing up without changes in the next version of the language, and even if it doesn’t change, it probably won’t show up widely in other browsers for a while.

    Overview

    First-class coroutines, represented as objects encapsulating suspended execution contexts (i.e., function activations). Prior art: Python, Icon, Lua, Scheme, Smalltalk.

    Examples

    The “infinite” sequence of Fibonacci numbers (notwithstanding behavior around 253):

    function* fibonacci() {
        let [prev, curr] = [0, 1];
        for (;;) {
            [prev, curr] = [curr, prev + curr];
            yield curr;
        }
    }
    

    Generators can be iterated over in loops:

    for (n of fibonacci()) {
        // truncate the sequence at 1000
        if (n > 1000)
            break;
        print(n);
    }
    

    Generators are iterators:

    let seq = fibonacci();
    print(seq.next()); // 1
    print(seq.next()); // 2
    print(seq.next()); // 3
    print(seq.next()); // 5
    print(seq.next()); // 8
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why I get this error? Page not found (404) Using the URLconf defined in
I found this code to get the image size on javascript: function getImgSize(imgSrc) {
I have a CKEditor in my page. Like this <h:head> <title>Facelet Title</title> <script type=text/javascript
I've found this page about the Twitter search API and some operators : http://search.twitter.com/operators
I found this page describing the Muenchian method, but I think I'm applying it
I was reading this page and I found the following statement: MVC in Java
I came across this page: Plotting Tools where I found a set of tools
I would like to display tagcloud in my home page. Found this wordpress flash
This page displays beautifully in firefox but i get all kinds of problems when
Not so much a question to help my own programming, but I found this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.