简体   繁体   English

带有'yield'关键字的Javascript生成器

[英]Javascript generators with the 'yield' keyword

I'm experimenting with HTML5's new canvas tag, in which I render and animate some simple shapes. 我正在尝试HTML5的新画布标签,我在其中渲染和动画一些简单的形状。 My canvas's script has the following function: 我的画布脚本具有以下功能:

function initializeSquarePositions(rows, columns) {
    for (var x = 0; x < canvas.width; x += canvas.width / columns)
        for (var y = 0; y < canvas.height; y += canvas.height / rows)
            yield {x: x, y: y};
}

For some reason, this code executes wonderfully in Firefox, but it does not work at all in Chrome. 出于某种原因,此代码在Firefox中执行得非常好,但在Chrome中根本不起作用。 Both browsers are the latest version, and I have my script tag marked as version=1.8 (version=1.7 didn't work either). 这两个浏览器都是最新版本,我的脚本标签标记为版本= 1.8(版本= 1.7也不起作用)。

Is the 'yield' keyword not working in Chrome or something? “yield”关键字在Chrome中无效吗? I sure hope it does; 我当然希望它能做到; generators make for cleaner code! 发电机使代码更清洁!

I couldn't find any concrete yes or no answers to that question. 我找不到任何具体的是或否答案。

Iterators and Generators are (for now) Mozilla-extensions, this means that you will be able to use them only on Mozilla Implementations (JavaScript (TM)). 迭代器和生成器(现在)是Mozilla扩展,这意味着您只能在Mozilla实现(JavaScript(TM))上使用它们。

I said "for now" because those features will be probably introduced in the next version of the ECMAScript Standard, ECMAScript Harmony . 我说“暂时”,因为这些功能可能会在下一版ECMAScript标准ECMAScript Harmony中引入。

Is the 'yield' keyword not working in Chrome or something? “yield”关键字在Chrome中无效吗?

That's it. 而已。 Sorry. 抱歉。 yield and let aren't in Chrome (or Opera, or Safari, or IE) yet. yieldlet不在Chrome(或Opera,或Safari或IE)中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM