From: Stefan Weiss on
On 27/07/10 10:51, Stefan Weiss wrote:
> What's wrong with
>
> var MYNS = MYNS || {};
>
> ?

I should have read the entire thread before replying... sorry.


--
stefan
From: Ry Nohryb on
On Jul 27, 4:36 am, David Mark <dmark.cins...(a)gmail.com> wrote:
>
> If the team is having trouble wrapping their brains around global
> variable declarations (a la Jorge)

LOL.
--
Jorge.
From: Stanimir Stamenkov on
Mon, 26 Jul 2010 15:26:53 +0300, /David Mark/:

> ... They should also understand that there is no such thing
> as a "namespace" in JS. It's a global variable referencing an
> object. Calling it something else implies that it is somehow
> different from all other native objects, which it is not. That's
> where the confusion starts.

In my initial post I've written: "use a global variable acting as
namespace". Do you think the given wording is confusing?

In C++ and Java classes act as namespaces for their static members,
for example, but classes are not namespaces. Java also doesn't have
namespaces but packages. I think most people are aware, number of
concepts are established differently in different programming
environments.

--
Stanimir
From: Scott Sauyet on
David Mark wrote:
> On Jul 26, 9:32 pm, Scott Sauyet <scott.sau...(a)gmail.com> wrote:

>> The one practical advantage to [a single-line namespace declaration]
>> I know of is that it's much easier to introduce it in the sort of
>> environment the OP describes, when there is a team that needs to be
>> convinced that namespaces are not difficult.  It's easy to point to
>> a one-liner to demonstrate how easy it is to start using namespaces.
>
> If the team is having trouble wrapping their brains around global
> variable declarations (a la Jorge), then they've got bigger problems
> to sort out.  

Perhaps, but most teams do have their issues. If the issues can be
reduced by one using such a simple method, it certainly seems worth it
to me.

> They should also understand that there is no such thing
> as a "namespace" in JS.  It's a global variable referencing an
> object.  Calling it something else implies that it is somehow
> different from all other native objects, which it is not.  That's
> where the confusion starts.

I'm not sure what "namespace" means to you that a global variable
referencing an object would not cover. I like Wikipedia's definition:

| A namespace is an abstract container or environment created
| to hold a logical grouping of unique identifiers or symbols
| (i.e., names).

-- <http://en.wikipedia.org/wiki/Namespace_%28computer_science%29>

That's certainly how I use such constructs in Javascript.

--
Scott
From: Asen Bozhilov on
David Mark wrote:
> Asen Bozhilov wrote:

> > Both are not good. First, because use undeclared assignment. In the
> > second approach the problem is in ES5 environment. The `this'
> > associated with that execution context in strict mode must be
> > `undefined'. So you will get TypeError.
>
> I don't see the strict mode problem to be an issue as you would have
> to explicitly require strict mode in the code.

Definitely, but I would prefer to use Á code which I can easy migrate
in ES5 environment with strict-mode. Although I do not like some
things from ES5 during development process I would prefer to use
strict variant of the language.