在这个页面中,我找到了一个新的JavaScript函数类型:
// 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;
}
}
Run Code Online (Sandbox Code Playgroud)
我已经知道了什么yield,let以及[?,?]=[?,?]做的,但不知道什么function*是注定的.它是什么?
我一直熟悉Koa(http://koajs.com/).许多示例包括星号代替函数名称.例如,在hello world示例中有:
var koa = require('koa');
var app = koa();
app.use(function *(){
this.body = 'Hello World';
});
app.listen(3000);
Run Code Online (Sandbox Code Playgroud)
这颗星是什么意思?
我遇到了这个偶像:function* (){ ... }从这个页面https://github.com/jmar777/suspend,不知道它做了什么.
谁能解释一下?谢谢!