★ wanayoo — archive 1999 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/returnNouvelle recherche | Portail wanayoo

Apply your JS skills to key Mozilla projects as an MDN Fellow! http://mzl.la/MDNFellowship

mozilla
Your Search Results

    Generator.prototype.return()

    This is an experimental technology, part of the ECMAScript 6 (Harmony) proposal.
    Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future version of browsers as the spec changes.

    Summary

    The return() method returns the given value and finishes the generator.

    Syntax

    gen.return(value)

    Parameters

    value
    The value to return.

    Return value

    Returns the value that is given as an argument to this function.

    Examples

    Example: Using return()

    The following example shows a simple generator and the return method.

    function* gen() { 
      yield 1;
      yield 2;
      yield 3;
    }
    
    var g = gen();
    
    g.next();        // { value: 1, done: false }
    g.return("foo"); // { value: "foo", done: true }
    g.next();        // { value: undefined, done: true }
    

    Specifications

    Specification Status Comment
    ECMAScript 6 (ECMA-262)
    The definition of 'Generator.prototype.return' in that specification.
    Draft Initial definition.

    Browser compatibility

    Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
    Basic support ? 38 (38) ? ? ?
    Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
    Basic support ? ? 38.0 (38) ? ? ?

    See also

    Document Tags and Contributors

    Contributors to this page: fscholz
    Last updated by: fscholz,