Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have spent a lot of time with <code>yield</code> recently, and bobince isn't completely wrong, but Chrome 31 does not interpret JavaScript version to 1.7 blocks, even with the Experimental JavaScript flag turned on (chrome://flags/#enable-javascript-harmony). Due to implementation differences between Chrome 31 and Firefox, Tymon Sturgeon's method is unable to detect <code>yield</code> in Chrome 31 with Experimental JS on, although it is very close. With a few modifications, it can detect the existence of <code>yield</code> for both Firefox and Chrome 31 with Experimental JS on.</p> <p>First I'll quickly cover the <code>yield</code> differences (writing it the long way for clarity):</p> <p>In Firefox:</p> <pre><code>var fooGen = function(){ yield 1; yield 2; }; var iterator = fooGen(); console.log(iterator.next()); // prints 1 console.log(iterator.next()); // prints 2 </code></pre> <p>In Chrome 31 with Experimental JavaScript enabled:</p> <pre><code>// Note the * var fooGen = function*(){ yield 1; yield 2; }; var iterator = fooGen(); console.log(iterator.next().value); // prints 1 console.log(iterator.next().value); // prints 2 </code></pre> <p><code>.value</code> is required in Chrome because it yields an object, but more importantly, the generator requires a "*" in the function definition. Also, I could not find a way to create a generator from the capital "F" Function: <code>new Function('', '{yield 5;}');</code> in Chrome. If you know how, leave a comment below.</p> <p>To properly detect <code>yield</code> in Firefox and Chrome, I have used a bit of code with some back and forth:</p> <pre><code>&lt;script type="application/javascript"&gt; var can_yield = (function(){ try { // Assuming Chrome's generator syntax var funcUsingYield = new Function('', '{ var interp = function* generator(){ yield true; }}'); return true; } catch(e) { return false; } })(); &lt;/script&gt; &lt;script type="application/javascript;version=1.7"&gt; // Redefine the `can_yield` function inside a JS1.7 block. Probably safe to simply return true can_yield = (function(){ try { return eval("!!Function('yield true;')().next()"); } catch(e) { return false; } })(); &lt;/script&gt; &lt;script type="application/javascript"&gt; if(!can_yield) { alert("Can't Yield!"); } &lt;/script&gt; </code></pre> <p>Tested in:</p> <ul> <li><strong>Firefox 25</strong>: <code>yield</code> works</li> <li><strong>Chrome 31</strong> with Experimental JS <strong>On</strong>: <code>yield</code> works</li> <li><strong>Chrome 31</strong> with Experimental JS <strong>Off</strong>: <code>yield</code> does not work</li> <li>and <strong>IE10</strong>: <code>yield</code> does not work</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload