On dropping @names

Brendan Eich brendan at mozilla.com
Wed Dec 26 19:40:08 PST 2012

Rick Waldron wrote:
> On Wednesday, December 26, 2012, Brandon Benvie wrote:
>     I guess to sum up what I think Domenic was saying: people hoist
>     var declarations so that their code acts the way the engine is
>     going to execute it in order to prevent a mismatch between
>     expectations and result. If there wasn't a reason to do that (AKA
>     TDZ-UBI) then it wouldn't be done, because it's not otherwise
>     desirable to do.
> Conversely, many also believe there is benefit in having a single 
> place in a function to locate all of the formal parameter names 
> and initialized identifiers. Assignment close to use also embraced by 
> this pattern.

Well, vacuously if you force initialization in the declaration, but 
otherwise, manually hoisting can move a var very far from its uses.

> Subjectively, this makes it easier to identify free vars used in the 
> function.

I've heard that too. It's a bit of a chore to hoist manually, though, 
and I've noticed that those who say they do it tend to grow unhoisted 
declarations in their code over time.

> Many also believe that hoisting is an excellent feature, not a weirdness.

For functions, I can defend hoisting, although if I had had more time, I 
might have done a let ... in ... or BCPL'ish equivalent form that groups 
the recursive bindings. For vars hoisting is pretty much an 
implementation abstraction leak in JS1 :-P.


More information about the es-discuss mailing list