Design principles for extending ES object abstractions

Luke Hoban lukeh at
Fri Jul 8 16:05:13 PDT 2011

I agree wholeheartedly with these.  In fact, I'd go further on (2), and say "Anything that can be done declaratively can also be done imperatively, using ES5 syntax". will have two syntaxes running on a single runtime, sharing objects across a shared heap.  I think we should ensure that all relevant semantics of are pushed down into the shared runtime, and exposed through libraries available to both syntaxes, to ensure full interoperability between the two.

The one additional place I know of in existing proposals where I believe this principle is not yet met is the ability to define a module from ES5 syntax, and consume it from syntax.  Inline with these principles, I expect the module loader API should offer a way to imperatively define a module that can be later loaded using module loader APIs.


From: es-discuss-bounces at [mailto:es-discuss-bounces at] On Behalf Of Allen Wirfs-Brock
Sent: Friday, July 08, 2011 3:49 PM
To: es-discuss at
Subject: Design principles for extending ES object abstractions


I wanted to generalize this a bit.  In designing "classes" and other new ES abstractions there are a couple design principles that I think it is important that we follow:

1) Everything works with plain objects.

Objects (and functions) are the primitive abstraction mechanisms of ES.
Any new functionality we add must be applicable and available to plain vanilla singleton objects.
Anti-example:  super keyword that is only available in a class declaration
Acceptable solution: super keyword is available for both class declaration and object literals.

2) Anything that can be done declaratively can also be done imperatively.

Imperative/reflective object construction is a power feature of ES that has been widely exploited by everyday developers as well as  metaprogrammers.
Any new object capabilities that we make available via declarative  constructs must also be available via an imperative API.
Anti-example: functions definitions using super keyword may only occur within an object literal or class declaration.
Acceptable solution: Object.defineMethod can be used to bind an externally defined function that uses the super keyword to a specific object.

I don't expect that anybody will significantly disagree with either of these principles.  But I think it is good to explicitly articulate them and make sure we have agreement one them. Sometimes we spend a lot of time discussing an idea that doesn't or can't conform to these principles.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list