I've been doing some research on object literals and such. I am creating a game that has various properties from my player. These prorpeties are stored in multiple groups, such as his ship and all the properties for that, his wepaon and all the properties for that, etc..As a result I have been storing these properties into object literals.
I don't want my object values to be overwritten. I ran across an article here http://www.gabordemooij.com/jsoop.html, and curious if something like this would be a healthy start to keeping object values from easily being overwritten...
Cat = {
createNew: function() {
var cat = {};
var sound = "meow"; //sound is local
cat.makeSound= function(){
//can reach sound from here
alert( sound );
}
return cat;
}
}
var cat = Cat.createNew();
cat.makeSound();
//but can't reach sound from here
alert(cat.sound); //fail!