3 ms·
It’s about strictness scoping. https://old.reddit.com/r/webdev/comments/v877zq/why_cant_you_use_strict_in_function_with/ibp4lpd/ https://old.reddit.com/r/webdev
by chrismorgan 3y ago
It’s about strictness scoping. https://old.reddit.com/r/webdev/comments/v877zq/why_cant_you_use_strict_in_function_with/ibp4lpd/ https://old.reddit.com/r/webdev/comments/v877zq/why_cant_you... gives a decent explanation, and https://github.com/rwaldron/tc39-notes/blob/d0c651b358b361b0855cfe7af9ba0b76cab73949/es7/2015-07/july-29.md#611-the-scope-of-use-strict-with-respect-to-destructuring-in-parameter-lists https://github.com/rwaldron/tc39-notes/blob/d0c651b358b361b0... is good and technical.
- lakpan 3y agoThat seems weird to me. Does strict mode affect parsing? I thought that parsing completed before execution, so why couldn’t the parser generate the same AST for these two functions? (a) => a === undefined ? 1 : a (a = 1) => a
- jraph 3y ago> Does strict mode affect parsing? Actually, yes. default parameter values could contain things that are allowed in sloppy mode and are syntax errors in strict mode. For instance, a leading zero in numbers without explicitly specifying the base, duplicate property names, the with statement, new reserved words and using delete on a variable name. You need to disallow those in the parameter values in strict mode, but you only know this after encountering the "use strict" marking in the function body if you were not already in strict mode. You can make a parser able to do this, but it is more complex. I guess they decided that this complexity is not worth it.
- jraph 3y agoThanks, very interesting. A bit hard to understand this transcript without context but it really reads like SpiderMonkey and Chakra were actually able to parse this. V8 people didn't like it, the others were like "ok, whatever" and they ended up disallowing it in the spec. I guess it allows simplifications in the parsers by not having a "strict or sloppy, don't know" mode for default parameter values, while not blocking actual use cases.