3 ms·
Other languages declare some language version to apply to a given source file, like C++'s --std=c++17 or Rust's (planned) epochs. A word being reserved in a new
by scottlamb 9y ago
Other languages declare some language version to apply to a given source file, like C++'s --std=c++17 or Rust's (planned) epochs. A word being reserved in a new standard/epoch/whatever doesn't break existing code using an older one.
Why doesn't Javascript start doing something similar? One mechanism for it could be a magic comment at the top of the file (sort of like DOCTYPE or #!/usr/bin/env python3).
- LukeShu 9y agoIndeed, in the past there was "use strict"; to enable language improvements in ES5. This type of string-command is a no-op command if the implementation doesn't recognize the string as special; you put the string-command in there to opt-in to any breaking changes, and then feature-detect to see if things are there in case you're running on an older implementation without those changes. User hrajchert suggested putting this change behind `"use es2019";`. However, in this case that would be tricky, as the change isn't in language semantics, but in the standard library's Array type. If there are multiple scripts on a page that interact, some of which "use es2019" and some of which don't, how do you handle an array being passed between them?
- deleted 9y ago[deleted]