I'm localizing a menu and I want to assign a declared array to an object property in that way:
var menuListLocal=["Home","Play","Options","Exit"];
var menu_Controller={
_menuList: menuListLocal,
// .... //
}
Sorry if it is too obvious.
Thanks.
I'm localizing a menu and I want to assign a declared array to an object property in that way:
var menuListLocal=["Home","Play","Options","Exit"];
var menu_Controller={
_menuList: menuListLocal,
// .... //
}
Sorry if it is too obvious.
Thanks.
Share edited Aug 20, 2009 at 16:12 i_am_jorf 54.7k15 gold badges136 silver badges225 bronze badges asked Aug 20, 2009 at 16:10 VeilkrandVeilkrand 3551 gold badge3 silver badges17 bronze badges 3- 1 It isn't clear from your post what your problem is. – i_am_jorf Commented Aug 20, 2009 at 16:11
- 3 Uuhm this should work? Only thing, you should remove the last , Only use a , to separate properties not at the end... – Ropstah Commented Aug 20, 2009 at 16:13
- I second @jeffamaphone, not sure what the problem is... – localshred Commented Aug 20, 2009 at 16:15
2 Answers
Reset to default 3What you have should work, keeping in mind ropstah's ment.
var menuListLocal=["Home","Play","Options","Exit"];
var menu_Controller={
_menuList: menuListLocal,
_other: 'Something'
};
Usage sample:
var home = menuListLocal._menuList[0];
Strange that it's not working. If John's answer doesn't clear it up for you, try explicitly setting it in an init() method on your menu_Controller:
var menuListLocal=["Home","Play","Options","Exit"];
var menu_Controller={
_menuList: null,
init : function (){
menu_Controller._menuList = menuListLocal;
}
}
menu_Controller.init();