Hacker News new | past | comments | ask | show | jobs | submit login
Unambiguous JavaScript Grammar (github.com/bmeck)
70 points by ingve on June 18, 2016 | hide | past | favorite | 14 comments



Author seems to be mostly concerned by code loaded as a module being treated as strict 100% of the time.

Literally every difference that they list is strict mode (and the usual misunderstanding of |this|)


Yes that is the main difference along with top level return statements


What usual misunderstanding of |this| are you referring to?


People keep trying to apply lexical scope for |this| when it is always the left hand of the function refernece expression, e.g.

Lhs.foo()

Lhs[foo]()

And

Foo() // where lhs is implied to be the scope object defining Foo

The last one seems to be what makes everyone super confused, but it is logically:

GetScopeWith("foo").foo()

Strict mode changes /one/ thing about|this|: whether the value of |this| undergoes object coercion


Might mean that in a module, `this` represents the environment the module was loaded in (rather than `undefined`), or `window|global` if not modularly loaded? I'm not sure either....


    function foo(value) {
      value = value || '';
      var args = [].slice.call(arguments);
      args.unshift(this);
      return args;
    }
    foo(null);
    export {};
If your module does nothing but side-effects during load time, screw you.


That's generally and edge case and totally supported under the proposal by being explicit about with respect to `export`.

I think being explicit about the intent of your code is a good thing after all.


Why can't this be done as a module declaration? I.e. a file would be prefaced with `module Main;` to declare that it's a module and give it a name.


That requires modification to every file using ES modules, and new syntax. The proposed solution only requires modifying files which do not have an import or export statement, and does not need new syntax.


Who else thinks that this whole mess around trying to implement ES modules demonstrates that they were a bad idea to begin with?


Where is the BNF?


There's no BNF, this is not a language spec or full grammar, it just describes an addition to the existing grammar to denote a module.


yeah, i just use it for scripting browsers, which don't support most of that shenanigans. for real work i use languages that are not a week old. I have no idea what exactly is being discussed there, other then it requires a syntax hack with `exports {}` to break the new standard.


> I have no idea what exactly is being discussed there

Criticizes it anyway .. something something JS is bad. Thanks for your high level input.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: