Skip to content

Instantly share code, notes, and snippets.

@glinesbdev
Created October 21, 2014 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glinesbdev/79e345f8f1f575188a8c to your computer and use it in GitHub Desktop.
Save glinesbdev/79e345f8f1f575188a8c to your computer and use it in GitHub Desktop.
Dynamic object building in JS
var superBlinders = [ ["Firestorm", 4000], ["Solar Death Ray", 6000], ["Supernova", 12000] ];
var lighthouseRock = {
gateClosed: true,
weaponBulbs: superBlinders,
capacity: 30,
secretPassageTo: "Underwater Outpost",
numRangers: 0
};
function addRanger(location, name, skillz, station) {
location["numRangers"]++;
location["ranger" + location["numRangers"]] = { name: name, skillz: skillz, station: station };
}
addRanger(lighthouseRock, "Nick Walsh", "magnification burn", 2);
addRanger(lighthouseRock, "Drew Barontini", "uppercut launch", 3);
addRanger(lighthouseRock, "Christine Wong", "bomb defusing", 1);
lighthouseRock.numRangers #=> 3
lighthouseRock.ranger1.name #=> "Nick Walsh"
// And so on and so forth...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment