>
> That said, it has one problem -- base classes. You can't seal them
> because the constructor in the extended class would fail (I tried it)
> and so the base classes would always have to remain unsealed which
> means you either (1) understand that or (2) always use an extended class
> if you care for level of code safety.
One idea that I've been playing around with: instead of thinking about
class property definitions in terms of normal object properties, what if
they were sugar for a private field with a getter and setter? For instance,
class A {
x = 100;
constructor() { Object.seal(this) }
}
is sugar for:
class A {
#x = 100;
get x() { return this.#x }
set x(value) { this.#x = value }
}
If we did it like this, then it should work even with subclasses.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss