Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of '{ }' in javascript

What does assigning a variable to {}, mean? Is that initializing it to a function? I have code in a javascript file that says this

GLGE.Wavefront = function(uid) {
    GLGE.Assets.registerAsset(this,uid);
    this.multimaterials = [];
    this.materials      = {}; // <---
    this.instances      = [];
    this.renderCaches   = [];
    this.queue          = [];
};

how is that assignment different from an array? Is it a type of array?

like image 753
Zeeno Avatar asked Jul 26 '11 14:07

Zeeno


2 Answers

What does assigning a variable to {}, mean?

It is an object literal (with no properties of its own).

Is that initializing it to a function?

No, that would be = function () { }.

how is that assignment different from an array?

An array has a bunch of features not found in a basic object, such as .length and a bundle of methods.

Objects are often used to store arbitrary key/value pairs. Arrays are for ordered values.

like image 163
Quentin Avatar answered Sep 29 '22 00:09

Quentin


This is javascript object notation. Particularly {} means empty object, the same as new Object();. See json.org.

like image 39
iafonov Avatar answered Sep 29 '22 00:09

iafonov