With ECMAScript 5, one could do the following to share a property between all objects of a class, accessible through each object same way as if it were a property defined on each such object:
function Message {
}
Message.prototype.importance = "normal";
Evaluating (new Message()).importance
would yield the value "normal"
, but the essential thing here is that importance
is the property of the prototype object, so no matter how many message objects one creates, given how they all share the same prototype, the property and thus its value are shared.
I can't seem to find out how I can define a property like that with an ES6 class. From what I understand, ES6 classes still use prototype based inheritance, although I am also aware that the standard describes a class as a distinct first-class citizen.
Assume I define the class as follows:
class Message {
}
Is there any new (ES6) syntax that allows me to define the aforementioned property. I know I can add Message.prototype.importance = "normal"
below the class definition, but I am curious if there is any ES6-specific syntax for this?