Prev: FAQ Topic - What does the future hold for ECMAScript? (2010-07-20)
Next: How to change "margin-top" using JS
From: MC on 30 Jul 2010 15:13 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
From: Stefan Weiss on 30 Jul 2010 20:04 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
From: MC on 30 Jul 2010 22:36
"Stefan Weiss" <krewecherl(a)gmail.com> wrote in message news:79adnTV0wq0F9c7RnZ2dnUVZ8vqdnZ2d(a)giganews.com... > 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 Stefan, Thank you, that seems to work fine. I googled and looked in several books and did not see an example of this. Mica |