On Jan 19, 2015, at 5:32 AM, Fabrício Matté wrote:
> Your second example may break if the constructor is called via
> `.call()`/`.apply()` or as a CallExpression : MemberExpression or if it has
> been `.bind()`ed. Although these may look like corner cases, a good transform
> should cover these cases, especially CallExpression : MemberExpression as it
> is very common in Node.js land to have constructors exported as properties of
> an exported object.
This style of `this` testing is what was necessary to distinguish [[call]] from
[[construct]] under the old ES6 @@create design. And the above edge cases were
what complicated all of the built-in constructors (and required branding checks
and initialization flags) to fully cover.
It was the complexity of correctly identifying those edge cases which lead us
to recommending that JS code should never try to do it, and JS developers
shouldn't try to defined classes whose constructors did an implicit 'new' when
called.
With 'new.target' that complexity all goes away and I see no particularly
reason to discourage constructors that 'new' themselves when called as
functions.
Allen
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss