migrating `let' and `const'

Jeff Walden jwalden+es at MIT.EDU
Tue Nov 15 10:13:00 PST 2011


On 11/15/2011 07:17 AM, Andy Wingo wrote:
> SpiderMonkey appears to allow them, as does V8 with --harmony, but V8
> without --harmony and JSC both abort on `const' in strict mode.

If you opt into a version supporting 'let', you get 'let' functionality.  If you don't, 'let' is a strict reserved keyword, so use of it is a syntax error.  Thus the name is reserved for future use in code that hasn't made an effort to use 'let' functionality; but if it has indicated it wants to use 'let', that use will keep working.  (Although how it works might change at the margins after standardization, as Brendan notes.  But relatively minor changes in semantics are much easier to do than wholesale disabling.)

> Likewise, none of the major engines abort on `const' in non-strict mode.

'const' is just old, far older than 'let', and has never been guarded behind a version check.  Other engines probably have mostly JS on the web to target, but SpiderMonkey has Firefox code, extension code, and so on to deal with as well.  It didn't seem practical to disable it given all those other users, some of whom definitely do want to use 'const' in strict mode code.  And its semantics now are "close enough", as Brendan notes, if you're just using it the natural way with straight-line, run-once-per-activation code.  So it works unconditionally in SpiderMonkey.  (It's perhaps worth noting you can compile SpiderMonkey without 'const' support at all, although that frob's likely under-tested.)

Jeff


More information about the es-discuss mailing list