2007/12/5, Keryx Web <[EMAIL PROTECTED]>:
>
> Stanislav Malyshev skrev:
> >> +1 for putting namespaces on the backburner and taking the time to
> >> get it 100% right ...
> >
> > What's "100% right"? Any proposals (besides braces)?
> >
>
> Actually I did mention an alternative a while ago, and that would be to
> learn from ECMAScript 4. This is from John Resigs talks:
>
> import dojo.query;
> import jquery.query;
>
> use namespace dojo;
> query("#foo") // using dojo
>
> use namespace jquery;
> query("div > .foo") // using jquery


But ECMAScript 4 namespaces are not even like the namespaces we're
discussing here. In that language there's both packages and namespaces.
Packages define class grouping and namespaces work like visibility
declarations (public/protected/private). In the above example what's
happening behind the scenes is the following:

package dojo {
    public namespace dojo;
    dojo function query(....) { .... }
}
package jquery {
    public namespace jquery;
    jquery function query(....) { .... }
}

The use namespace directive in ECMAScript4 means:
"I want to be able to see the constructs marked with the namespace provided"

Which is different to:
"Bring that construct from that scope to my current scope" (import)

The first one affects every name and scope, you'll see everything the
"namespace" has to offer, and "namespaces" exist as an object. the second
one is just, practically speaking, a way to make a shortcut for a larger
name.

This makes sense when you're working with E4X because XML namespaces are
binded to namespaces in code. But take an advice from one that has been
working with an ECMAScript4 compliant language: KEEP AWAY FROM ECMASCRIPT4
NAMESPACES.

Reply via email to