mirror of
https://github.com/wu736139669/Monkey-Test.git
synced 2026-08-05 05:55:46 +00:00
20 lines
821 B
Markdown
20 lines
821 B
Markdown
# Semantic differences between original ES6 and transpiled ES3
|
|
|
|
### Referenced (inside closure) before declaration
|
|
`defs.js` detects the vast majority of cases where a variable is referenced prior to
|
|
its declaration. The one case it cannot detect is the following:
|
|
|
|
```javascript
|
|
function printx() { console.log(x); }
|
|
printx(); // illegal
|
|
let x = 1;
|
|
printx(); // legal
|
|
```
|
|
|
|
The first call to `printx` is not legal because `x` hasn't been initialized at that point
|
|
of *time*, which is impossible to catch reliably with statical analysis.
|
|
`v8 --harmony` will detect and error on this via run-time checking. `defs.js` will
|
|
happily transpile this example (`let` => `var` and that's it), and the transpiled code
|
|
will print `undefined` on the first call to `printx`. This difference should be a very
|
|
minor problem in practice.
|