Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Namespace Array

0 views
Skip to first unread message

MC

unread,
Jul 30, 2010, 3:13:31 PM7/30/10
to
I want to create an array that would be namespaced. What is the proper way
to do that? (Using the following two examples)

--Normal namespace object
MYNS.CarTypeCd = function() {}

--Normal Array
var CarTypeCd = new Array();
CarTypeCd [0] = new Array("Ford", "Pinto");
CarTypeCd [1] = new Array("GM", "Suburban");

doing
MYNS.CarTypeCd = new Array();
gets a CarTypeCd is not defined error.

Thank you,
Mica

Stefan Weiss

unread,
Jul 30, 2010, 8:04:39 PM7/30/10
to
On 30/07/10 21:13, MC wrote:
> I want to create an array that would be namespaced. What is the proper way
> to do that? (Using the following two examples)
>
> --Normal namespace object
> MYNS.CarTypeCd = function() {}

Did you mean

MYNS.CarTypeCd = {};

?

> --Normal Array
> var CarTypeCd = new Array();
> CarTypeCd [0] = new Array("Ford", "Pinto");
> CarTypeCd [1] = new Array("GM", "Suburban");
>
> doing
> MYNS.CarTypeCd = new Array();
> gets a CarTypeCd is not defined error.

No, it doesn't?

How about this:

var MYNS = {
CarTypeId: []
};
MYNS.CarTypeId[0] = ["Ford", "Pinto"];
MYNS.CarTypeId[1] = ["GM", "Suburban"];

or even simpler:

var MYNS = {
CarTypeId: [ ["Ford", "Pinto"], ["GM", "Suburban"] ]
};


--
stefan

MC

unread,
Jul 30, 2010, 10:36:12 PM7/30/10
to
"Stefan Weiss" <krewe...@gmail.com> wrote in message
news:79adnTV0wq0F9c7R...@giganews.com...

Stefan,
Thank you, that seems to work fine. I googled and looked in several books
and did not see an example of this.
Mica


0 new messages