javascript - What is this variable type called? -
i looking though civclicker game code , found created variables little "sub variables" inside it. doesn't array me.
an example of variable initialization:
// initialise data var food = { name:'food', total:0, increment:1, specialchance:0.1 }, wood = { name:'wood', total:0, increment:1, specialchance:0.1 }, stone = { name:'stone', total:0, increment:1, specialchance:0.1 }, skins = { name:'skins', total:0, }, he later calls variables using:
food.total++; and on. if has information on type of variable greatful :)
these javascript objects. { .. } syntax known literal notation , 1 way of creating object. attributes between braces properties, or methods if value function.
the objects created using shorthand var syntax, same repeating var:
var = {}, b = {}; // same var = {}; var b = {}; there other ways of creating objects , setting properties, such as:
var food = new object(); food.total = 0; food['name'] = 'food'; you can instantiate function create object, whereby function acts class.
function food { this.total = 0; this.name = ''; } var f = new food(); f.total = 5; f.name = 'abc'; mdn working objects resource covers this.
Comments
Post a Comment