Meaning of '{ }' in javascript

后端 未结 7 673
余生分开走
余生分开走 2021-02-07 17:37

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 =          


        
7条回答
  •  情书的邮戳
    2021-02-07 18:07

    It does create an empty object.

    var myObj = {};
    

    Within an object you can define key/value pairs, e.g.:

    myObj.color = 'red';
    

    A value can be a function, too:

    myObj.getColor = function() { return this.color };
    

提交回复
热议问题