开发者

Javascript generators with the 'yield' keyword

I'm experimenting with HTML5's new canvas tag, in which I render and animate some simple shapes. 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. Both browsers are the latest version, and I have my script tag marked as ver开发者_如何学Pythonsion=1.8 (version=1.7 didn't work either).

Is the 'yield' keyword not working in Chrome or something? 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)).

I said "for now" because those features will be probably introduced in the next version of the ECMAScript Standard, ECMAScript Harmony.


Is the 'yield' keyword not working in Chrome or something?

That's it. Sorry. yield and let aren't in Chrome (or Opera, or Safari, or IE) yet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜