I want to be able to instantiate a JavaScript object as follows:
var c = new MyConfig({
'server': 'servername',
'kfc': true,
'code': true,
'test': true
});
Something like that. I want the individual attributes to be available with something like:
c.getConfig('nfc'); which should return true / false etc.
I get confused on little stuff like should I use literal or constructor function.
Can someone assist?
You don’t really need a special constructor; an object is perfectly suited to that.
And to access a property, it’s as simple as
c.kfc, orc['kfc']if you need to access the property dynamically.