On May 22, 2012, at 9:29 AM, Erik Arvidsson wrote:
> I think this proposal has one fatal flaw and that was what brought it
> down the last time we had a proposal which used the same concepts.
> Given:
>
> class C(x) {
> public method() {
> return x;
> }
> }
>
> It seems like the arguments to the constructor are in scope for the
> entire class body when they really aren't. The above would raise an
> error that "x is undefined".
This is indeed a valid concern, though I don't see it as a fatal flaw. It's
effectively the same issue that statics would pose if added to any existing
class proposal.
One way to address this concern is to put 'x' in scope in the method bodies,
but as a poisoned reference that raises an (early?) error. That helps ensure
that unexpected outer variables are not unintentionally captured.
The code above would be rewritten:
class C(public x) {
public method() {
return this.x;
}
}
On the other hand - this allows a sufficiently simpler representation of the
class than the max/min proposal:
class C {
constructor(x) {
this.x = x;
}
public method() {
return this.x;
}
}
Luke
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss