On Dec 19, 9:18 am, tlrobinson <[email protected]> wrote: > I encountered a very odd bug, apparently in my code, not Rhino, > assuming "yield" is a reserved word in Rhino. > > I don't understand this behavior at all. I just thought it was > interesting, and would be interested to hear an explanation. > > Here's some test cases (test on: Rhino 1.7 release 2 PRERELEASE 2008 > 07 28) > > if (!this.alert) > this.alert = print; > > var something = function() { alert("CORRECT!!!"); }, > other = function() { alert("WRONG."); }; > > var testA = function() { > var yield = something; > yield(); > }; > > var testB = function() { > alert(something); > var yield = something || other; > yield(); > }; > > var testC = function() { > var notYield = something; > notYield(); > }; > > var testD = function() { > alert(something); > var notYield = something || other; > notYield(); > }; > > alert("==== A ====") > try{testA();}catch(e){alert("EXCEPTION: "+e)} > alert("==== B ====") > try{testB();}catch(e){alert("EXCEPTION: "+e)} > alert("==== C ====") > try{testC();}catch(e){alert("EXCEPTION: "+e)} > alert("==== D ====") > try{testD();}catch(e){alert("EXCEPTION: "+e)}
"yield" is a reserved word only if the language is set for 1.7 (or, eventually, higher). From https://developer.mozilla.org/en/New_in_JavaScript_1.7: When using the JavaScript shell, you need to set the version you wish to use using the -version 170 switch on the command line or using the version() function: version(170); The features that require the use of the new keywords "yield" and "let" require you to specify version 1.7 because existing code might use those keywords as variable or function names. The features that do not introduce new keywords (destructuring assignment and array comprehensions) can be used without specifying the JavaScript version. --Norris _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
