On Fri, Apr 24, 2015 at 1:49 PM, Trevor Norris <
trev....@gmail.com> wrote:
> On Fri, Apr 24, 2015 at 11:13 AM, Erik Arvidsson <
a...@google.com> wrote:
>> That is the output I see.
>>
>>
http://jsbin.com/modiduziyi/1/edit?html,console
>
> It's the output you see because it's setting the _onreadable property
> when onreadable() is called. Not when the class is created, and
> changing a class after it's been created isn't allowed in strong mode
> right? Using the private declaration you suggested would result in the
> first printed output from my example.
>
>> > The point of the example is to show that doing this is impossible in strong
>> > mode. I realize this isn't how normal OOP languages work, but it's a
>> > usability advantage for JS and libraries that want to allow setting default
>> > callbacks for newly constructed objects.
>>
>> I might be missing your point here. JS uses class side inheritance .
>
> I'm not sure what you mean by "class side inheritance".
class Base {}
class Derived extends Base {}
assert(Object.getPrototypeOf(Derived) === Base)
>> The problem with strong mode is that the function object created from
>> the class declaration is non extensible so adding the property will
>> not work without adding new syntax AND semantics.
>
> Let me clarify, is it that the class can't be changed after it's been
> declared
Yes
> or that the resulting object from the constructor can't be
> mutated?
The object is born non extensible so existing writable data properties
can be updated.
You cannot add a property to the function object represented by a
class in strong mode since it is born non extensible.
class C {
constructor() {
assert.throws(() => {
C.newProp = 1;
});
assert.throws(() => {
C.m = 2;
});
}
static m() {}
}
assert(!Object.isExtensible(C));
new C();
To make this work we need to add new syntax and semantics. We are
working on coming up with a workable design for class properties.
https://gist.github.com/jeffmo/054df782c05639da2adb
--
erik