本文介绍了什么是“功能*”在JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在页面中,我发现了一个新的JavaScript功能类型:

  //注意:Firefox中不支持function * 
//删除星号以使此代码在Firefox 13中正常工作

function * fibonacci(){// !!!这是有趣的线!
let [prev,curr] = [0,1]; (;;)的
{
[prev,curr] = [curr,prev + curr];
yield curr;
}
}

我已经知道,但不知道 function *

不要打扰Google,这是使用星号搜索表达式()

解决方案

这是 EcmaScript.next 的提议语法。 p>

Mozilla的Dave Herman发表了一个关于。在他谈论发电机。



此前,他解释了Mozilla如何实验性地实施提出的语言变更,以帮助指导委员会。 Dave与Mozilla的首席技术官Brendan Eich(我想)和原来的JavaScript设计师紧密合作。



您可以在EcmaScript工作组wiki上找到更多的细节: http://wiki.ecmascript.org/doku.php?id=harmony:generators



工作组(TC-39)普遍认为EcmaScript.next应该具有某种生成器迭代器提案,但这不是最终的。

您不应该依靠这种显示,而不会在下一版本的语言中进行更改,即使没有更改,也可能不会在其他浏览器中广泛显示一段时间。


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).

解决方案

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.

这篇关于什么是“功能*”在JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 02:53