Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using let and yield in Firefox

Tags:

javascript

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 is a reserved identifier

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.

like image 867
Nathan Wall Avatar asked Jan 15 '13 05:01

Nathan Wall


1 Answers

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.

like image 139
iMom0 Avatar answered Oct 20 '22 18:10

iMom0