Herby Vojčík wrote:
class List (n) {
this.@arr = n === +n ? new Array(n) : [];
}.{
at (i) {
i = +i;
if (i>=0 && i<[email protected]) { return this.@arr[i]; }
else throw "Out of bounds: "+i;
}
size () { return [email protected]; }
}
[snip...]
List.{
from (array) {
var r = new this();
r.@arr = array;
return r;
}
};
This looks like a class-side extension (from is a "static method",
specifically an alternative constructor). So the class expression
evaluates to the prototype, but the class name when used as an
Identifier expression evaluates to the constructor? That's incoherent.
That is coherent with "new Foo" - 'Foo is the class' means 'new Foo
returns new instance'.
Yes, but your first example, class List(n) {...} cited above at the very
top, uses .{ to add what looks like prototype methods at and size. If
class List(n){...} evaluates to the constructor then you're adding these
to the constructor function, not to its prototype. You'd need
class List (n) {
this.@arr = n === +n ? new Array(n) : [];
}.prototype.{
at (i) {
i = +i;
if (i>=0 && i<[email protected]) { return this.@arr[i]; }
else throw "Out of bounds: "+i;
}
size () { return [email protected]; }
}
And of course to make this work when used as an expression that should
evaluate to the constructor function, tack on a .constructor at the end.
Was this just a mistake or are you trying to have class List(n){...}
evaluate to the prototype while List later evaluates to the constructor?
I am still confused by what you wrote and believe it does not hang together.
And that takes us around the hermeneutic cycle again, which was my point
about classes not reaching consensus easily or by shotgunning the design
space. You may hit something but not bring down the prize bird: the
right not-too-minimal and not-too-maximal classes.
/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss