Namespaces in ECMA

Jason Orendorff jason.orendorff at
Sun Jul 15 10:55:13 PDT 2007

On 7/15/07, Alexandre Bergel <Alexandre.Bergel at> wrote:
> The notion of namespace of ECMA 4 is very interesting. I spent some
> time in reading the new javascript description [1]. I try to
> understand whether a "stack of namespace" is present or not at
> runtime. [...]

Thanks for the question.  You're right, that wiki page doesn't seem
to say.

The scope of "use namespace" is determined statically.  So is the "set
of open namespaces" that the spec talks about.  When the spec says
"context", it means the lexical context. The runtime stack is not a factor.

When an expression like "this.update()" is evaluated, the runtime
searches the open namespaces, in order, until an "update" property is
found.  The sequence of namespaces to search is determined
statically.  The search happens at runtime, because you can't tell
statically which properties the runtime value of "this" will have.

> Is there a chance to get a fixed interpreter ?

Yes, in time.  Both the spec and the reference implementation are
works in progress.

For the impatient, this example can be munged into a form the
current interpreter can handle:

  >> namespace N1;
  >> namespace N2;
  >> N1 var x: int = 10;
  >> N2 var x : String = "hello";
  >> {use namespace N1; print(x);}


  >> namespace V2;
  >> class Component {function paint() {print("Component paint")}
function update() {this.paint()} V2 function paint() {print("Component
paint V2")}}
  >> {use namespace V2; var c = new Component; c.update();}
  Component paint


More information about the Es4-discuss mailing list