Why packages and namespaces?

Peter Hall peter.hall at memorphic.com
Mon Jan 28 17:10:33 PST 2008


Packages, combined with 'internal', are a specialized subset of
namespaces, with usage restrictions and a convenient syntax to cater
for a common use case. Namespaces are more general: any declaration
(local variables or any function or variable defined in a package,
class, structural type or dynamic object instance) may belong to a
namespace. ES4 namespaces also provide very neat integration with
namespaces in E4X.

Peter


On Jan 28, 2008 8:04 AM, Peter Michaux <petermichaux at gmail.com> wrote:
> Thanks for reposting Brendan's explaination. I did look around but
> didn't find it.
>
> On Jan 27, 2008 11:45 PM, liorean <liorean at gmail.com> wrote:
> > I think Brendan had a nice explanation of that some time back:
> >
> > On 10/08/2007, Brendan Eich <brendan at mozilla.org> wrote:
> > > There's more work to do, including rationalizing and minimizing
> > > concepts including units and packages.  A couple of notes:
> > >
> > > A package is a named pair of namespaces (public and internal), some
> > > rules for using those namespaces within the package body, and some
> > > special forms for importing names from the package's public namespace.
>
> [snip]
>
> Here is a concrete problem. I tried this in the reference implementation...
>
> package org {
>   public var ecmascript = {a: 1};
> }
>
> package org.ecmascript {
>   public var a = 2;
> }
>
> org.ecmascript.a   // 2
>
> How do I access the "org.ecmascript.a" that has value 1?
>
> How does the programmer writing the org package know that his "a" will
> be clobbered by the "a" in the  org.ecmascript package? Isn't the
> point of packages to avoid this type of problem?
>
> Thanks,
> Peter
>
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es4-discuss
>



More information about the Es4-discuss mailing list