Make method semantic identical in classes and literals

# Herby Vojčík (14 years ago)

Hello,

overall I believe in making classes and literals as close as possible. I think at least semantics of things they have in common should be identical.

In harmony:classes, this is written:

By default, data properties define enumerable prototype properties while method members define non-enumerable prototype properties. Members of non-const classes default to writable and configurable. Member adjectives, if present, override the default attributes of the property being defined.

(I take the liberty to treat const classes as special case, so) for (general) non-const classes, method are non-enumerable, configurable, writable. Declaring the method itself const (whatever syntax is adopted) probably changes it to non-configurable and non-writable.

I deem this semantics as the right one. We are in dynamic language and want to have our methods changeable, but non-enumerable is very nice property of a method. And if taking the case of static away for a moment, class is not any special thing: we can look at it as the literal describing the class's prototype object (which it, sort-of, does).

In harmony:object_literals, this is written:

If a property definition has the form of a FunctionDeclaration without the keyword function it is a non-enumerable, non-writable, non-configurable data property definition whose name is the function name. This is called a method definition.

(For data (not methods), the literal semantics is the same as for class, but) for methods, object literal extension treats method as fixed. I believe they should be non-enumerable, but writable and configurable, and only changed to fixed when explicitly stated as const (whetever syntax is adopted), so the semantics is the same as it is for classes.

What do you think?

Thanks,

# Herby Vojčík (14 years ago)

It seems this is a bug in harmony:object_literals. In full proposal of object literal (harmony:concise_object_literal_extensions), this is written:

If a property definition has the form of a FunctionDeclaration without the keyword function it is a non-enumerable data property definition whose name is the function name.

So it is non-enumerable, writable and configurable, as generally presumed for methods. Could it be fixed?

Herby

-----Pôvodná správa---

# Allen Wirfs-Brock (14 years ago)

As it stands right now there are still other more significant outstanding issues relating to both proposals that need to be addressed. As those get resolved we will make then as consistent with each other as makes sense. I think there is wide agreement that "methods" should be should be non-enumerable. There may be less agreement on whether they should be non-writable or non-configurable.

# Herby Vojčík (14 years ago)

Ok, thanks. If my opinion counts, then I am definitely at the side of "methods should be writable and configurable unless declared const". ;-)

Herby

-----Pôvodná správa---