An experiment using an object literal based class definition pattern

Sam Tobin-Hochstadt samth at ccs.neu.edu
Mon Aug 15 11:43:38 PDT 2011


On Tue, Aug 9, 2011 at 2:54 PM, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
> On Aug 9, 2011, at 10:23 AM, Bob Nystrom wrote:
>> On Mon, Aug 8, 2011 at 3:14 PM, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
>>> Yes, but by my rule above such a circularity would be an immediate name
>>> resolution error.  With class hoisting you have to actually analyze the
>>> inheritance chains to detect the error
>>
>> How does this play with modules? If I have two classes declared in different
>> modules (which I assume will a common case, if not the most common) then
>> hoisting or not hoisting won't help either way will it?
>
> Dave or Sam probably need to respond.  I haven't yet deeply internalized the
> semantics for mutually referential  modules in their proposal.  However, in
> general, I believe that such modules have to be processed as a unit and that
> would imply some implicit ordering of declarations.

There are two different ways that the semantics of mutually
referential modules matter.  The first is name visibility. Here there
shouldn't be any problems: the static semantics of such modules mean
both classes are visible (in terms of names and any other static
information) to each other.  The second is when the execution of the
class body happens.  Here, the order is determined by the order that
the modules are loaded, assuming that the classes are written at
module top-level.   The semantics [1] would then initialize each
module variable to undefined (unless it's a function), and then run
the module top-down.

For this particular case, modules won't make anything easier or harder
than putting them in a the same module together.  If that works
properly, then modules will work (possibly depending on ordering the
loads appropriately).  If some pattern with classes doesn't work in
one module, then spreading it across two modules won't change that,
either.

[1] http://wiki.ecmascript.org/doku.php?id=harmony:modules#run-time_execution
-- 
sam th
samth at ccs.neu.edu


More information about the es-discuss mailing list