What is cross browser support for JavaScript 1.7's new features? Specifically array comprehensions and the "let" statement
Asked Answered
B

3

16

https://developer.mozilla.org/en/New_in_JavaScript_1.7

A lot of these new features are borrowed from Python, and would allow the creation of less verbose apps, which is always a good thing. How many times have you typed

for (i = 0; i < arr.length; i++) {
    /* ... */
}

for really simple operations? Wouldn't this be easier:

[/* ... */ for each (i in arr)]

I think brevity is a great thing. Basically, it all comes down to IE in the end, though.

Does IE support these new features? What about other browsers?

Bevbevan answered 25/8, 2009 at 19:41 Comment(1)
IE doesn't support Javascript 1.7. IE has its own implementation - JScript - with its own extensions, such as conditional compilation.Besiege
P
8

No, when they say "JavaScript", they mean it literally: the ECMAScript engine used by Gecko. JScript and other engines (AFAIK) don't support these features.

EDIT: According to wikipedia, JavaScript 1.7 implements ECMAScript "Edition 3 plus all JavaScript 1.6 enhancements, plus Pythonic generators and array comprehensions ([a*a for (a in iter)]), block scope with let, destructuring assignment (var [a,b]=[1,2])". So these features are not part of ECMAScript.

Prepuce answered 25/8, 2009 at 19:54 Comment(0)
T
33

While this question is a bit old, and is marked "answered" - I found it on Google and the answers given are possibly inaccurate, or if not, definitely incomplete.

It's very important to note that Javascript is NOT A STANDARD. Ken correctly mentioned that ECMAScript is the cross-browser standard that all browsers aim to comply with, but what he didn't clarify is that Javascript is NOT ECMAScript.

To say Javascript "implements" ECMAScript means that Javascript includes ECMAScript, plus it's own proprietary extra non-cross-browser features. The for each example given by nicholas is an example of a proprietary feature added by Mozilla that is not in any standard, and therefore unlikely to be adopted by any other browsers.

Javascript 1.7 and 1.8 features are useful for extension development in XUL, but should never be used for cross-browser development - that's what standards are for.

Tantalum answered 5/2, 2010 at 19:20 Comment(2)
well said. the above pythonic example does not work in browsers other than firefoxMomentum
Harmony drafts for ECMAScript 6 look like they will add this feature :D ( wiki.ecmascript.org/doku.php?id=harmony:array_comprehensions )Fess
P
8

No, when they say "JavaScript", they mean it literally: the ECMAScript engine used by Gecko. JScript and other engines (AFAIK) don't support these features.

EDIT: According to wikipedia, JavaScript 1.7 implements ECMAScript "Edition 3 plus all JavaScript 1.6 enhancements, plus Pythonic generators and array comprehensions ([a*a for (a in iter)]), block scope with let, destructuring assignment (var [a,b]=[1,2])". So these features are not part of ECMAScript.

Prepuce answered 25/8, 2009 at 19:54 Comment(0)
S
1

In addition to IE not supporting it, it seems like the webkit based browsers (Safari, Chrome), despite claiming to have JS 1.7 support (actually executing script tags declared as being in JS 1.7), do not actually support any of these features which means that for now, JS 1.7 with its very nice features is limited to Geko browsers alone.

And because Webkit still executes scripts tagged as 1.7 only, this also means that we can't even fail gracefully but we'll just produce syntax errors on these browsers when we are using any of the new keywords or syntax.

Sheer answered 19/10, 2009 at 12:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.