简体   繁体   中英

Using let and yield in Firefox

I'm trying to use let and yield in Firefox. I am testing in both versions 18 and 21 (Nightly) and getting the same results.

Here's my really simple test script:

<html>
    <head>
        <title>test</title>
        <script type="text/javascript">
            'use strict';
            function a() {
                yield 5;
            }
        </script>
    </head>
    <body></body>
</html>

I get this error:

yield是保留的标识符

Similarly when I do a simple test with let I get "let is a reserved identifier", which is really frustrating because let has supposedly existed in Firefox since version 2 !

Strangely, if I execute the same code in Firebug it works!

I have tried various other strings in the type and language attributes of the script tag but have not found a magic one that works.

What's going on? How do I get this stuff working with a script tag?


Edit

Hmm, I see, so you must specify the version number. I had tried this, but for my original more complicated script which used web workers. Apparently using version=1.7 on a script which includes a web worker which includes a script that uses let and yield isn't good enough -- the web worker script still breaks... Then I tried reducing to simplest case but apparently didn't try version=1.7 in simplest case.

Thanks... Might post another question in a little bit (after searching) on how to get this working for web workers.

As mdn note said,

The yield keyword is only available to code blocks in HTML wrapped in a <script type="application/javascript;version=1.7"> block (or higher version)

So changing <script type="text/javascript"> to <script type="application/javascript;version=1.7"> will make it work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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