Created
October 21, 2014 04:46
-
-
Save glinesbdev/79e345f8f1f575188a8c to your computer and use it in GitHub Desktop.
Dynamic object building in JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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