Prototype Object on Classes

Lars T Hansen lth at
Mon Oct 29 00:24:15 PDT 2007

On 10/29/07, Yehuda Katz <wycats at> wrote:
> I couldn't quite determine this from the white-paper:
> If I define a class using the new class constructs, and do *not* make it
> dynamic, will I still be able to add new properties to the prototype object?


> If so, doesn't that provide a simple way to end-run around the entire
> lock-down that the new classical model provides?

Depends on your point of view.  (My view is that non-dynamic objects
are more useful to catch mistakes than to provide security.)

You still can't:
  - add properties to the object itself, since it's not dynamic -- you
get a run-time error
  - overwrite methods defined directly in the class (they're

Two more facts are relevant:
  - Strict mode will report as illegal references to properties not
defined in the class, if you've made the type of the object known
through an annotation.
  - When you define a class you get a prototype object that's
basically empty, but whose [[Prototype]] is Object.prototype, so there
are a couple of public properties there (toString etc).  You can add
properties to your class's prototype object, or objects anywhere on
the prototype chain, but basically anything defined in the class or
any of its base classes take precedence over the properties in the
prototype chain during lookup.

I now realize a couple of these details were not mentioned in the
paper but should have been.


More information about the Es4-discuss mailing list