Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi i've took over from a developer in our company and i've come across a jS file,

it declares
JavaScript
var requiredTemplates = {};


at the top of the page, and then later on does

JavaScript
requiredTemplates.toolBarTemplate = new Application.Template() *custom class
requiredTemplates.uploadTemplate = new Application.Template()


and so on,

what i can't understand is there is no reference to requiredTemplates, and where does it get these properties from, or they simply being made on the fly, can this be done, as i always thought associative arrays needed key value pair

like
JavaScript
 var requiredTemplates = {

     uploadTemplate: value;
}


any help in clearing that up would be great :-)
Posted

1 solution

They will be created on the fly. An alternative notation would be obj[key] = value.

They are not really associative arrays actually. It's an object with properties, so you won't be able to use it in the same way you would use an array (e.g. for (var i = 0, len = obj.length; i < len; ++i) {})

If you were to loop through it, you need to do as following
JavaScript
var o = {};
o.key1 = 'value1';
o.key2 = 'value2';

for (var key in o) {
    if (!o.hasOwnProperty(key)) continue;
    
    var value = o[key];
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900