Created
January 5, 2017 21:31
-
-
Save timruffles/4217725e9a9cae931078f13ec8d9101d to your computer and use it in GitHub Desktop.
hoistage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Difference between lintability/RTE of hoisting vs non-hoisted code | |
// ReferenceError: foo is not defined | |
// at <anonymous>:3:5 | |
try { | |
foo() | |
const x = 1; | |
const foo = () => x; | |
} catch(e) { | |
console.log(e) | |
} | |
// Hoisted version - you get a longer stack. | |
// Statically analysable (lintable): foo2 depends statically on const x, and foo2() is called before const x | |
// is in scope. | |
// ReferenceError: x is not defined | |
// at foo2 (<anonymous>:14:23) | |
// at <anonymous>:12:5 | |
try { | |
foo2() | |
const x = 1; | |
function foo2() { x }; | |
} catch(e) { | |
console.log(e) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment