No subject


Mon Sep 7 16:40:22 PDT 2009


In what sense are namespaces object-oriented?  As I understand the
term, object-orientation is a way of organizing a program around
objects that exchange messages.  There's nothing in this proposal that
deals with messaging or objects -- it seems to be a hierarchical
addressing scheme.

When you talk about namespace aliasing, should namespaces be treated
as first class?  If namespaces are aliasable, should they be marked
unconfigurable to prevent property deletion or is that up to the
namespace user?

When you talk about using the "with" statement with namespaces, what
problem are you trying to solve?  Is this meant to act as a poor-man's
java import?
Are you aware of the forward-compatibility problems that "with"
entails, and the effect it has on tools like YUI compressor, closure
compiler, etc.?

You mention java packages, which provide namespacing, and information
hiding.  Is it a goal for this scheme to extend to support information
hiding as well?  If so, how?

cheers,
mike


2009/12/1 Mark A. Ziesemer <online at mark.ziesemer.com>:
> I'd like to propose a "namespace()" function to the base ECMAScript
> language. =C2=A0(I previously thought about this only in terms of
> JavaScript, but I'm guessing it really belongs in ECMAScript?)
>
> I've previously blogged about this at
> http://blogger.ziesemer.com/2007/10/respecting-javascript-global-namespac=
e.html
> and http://blogger.ziesemer.com/2008/05/javascript-namespace-function.htm=
l
> , having actually become part of the review process for Firefox
> add-ons, being linked to from
> https://addons.mozilla.org/en-US/developers/docs/policies/reviews .
>
> While it is easy enough to define and use such a namespace function
> without it being included in the base language, the same could be said
> for the new String.trim functions that were just recently added.=C2=A0 I
> further feel that it would be very beneficial to have a "namespace"
> function declared in a standard rather than being used in an ad-hoc
> fashion, as this would hopefully discourage others from declaring a
> global "namespace" function that is unrelated or otherwise
> incompatible.=C2=A0 Finally, I think that this would be an important
> addition, especially with the amount of JavaScript being combined into
> web pages today.=C2=A0 (I could come up with many more reasons, but I thi=
nk
> this is a pretty good summary to start with.)
>
> I understand that at best, this would probably not appear until a
> later version of the specification.=C2=A0 In the meantime, it could
> continue to be supported as a back-portable extension, such as the
> Array extras.=C2=A0 However, most importantly, it would define this as pa=
rt
> of the (future) "language standard".
>
> Here is the actual function I am proposing, just so you don't have to
> click through:
>
> var namespace =3D function(name, separator, container){
> =C2=A0 var ns =3D name.split(separator || '.'),
> =C2=A0=C2=A0=C2=A0 o =3D container || window,
> =C2=A0=C2=A0=C2=A0 i,
> =C2=A0=C2=A0=C2=A0 len;
> =C2=A0 for(i =3D 0, len =3D ns.length; i < len; i++){
> =C2=A0=C2=A0=C2=A0 o =3D o[ns[i]] =3D o[ns[i]] || {};
> =C2=A0 }
> =C2=A0 return o;
> };
>
> Example of use:
>
> namespace("com.example.namespace");
> com.example.namespace.test =3D function(){
> =C2=A0alert("In namespaced function.");
> };
>
> Or, as one statement:
>
> namespace("com.example.namespace").test =3D function(){
> =C2=A0alert("In namespaced function.");
> };
>
> Either is then executed as:
>
> com.example.namespace.test();
>
>
> Thanks for your consideration.
>
> --
> Mark A. Ziesemer
> www.ziesemer.com
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>


More information about the es-discuss mailing list