开发者

javaScript: can someone explain this

开发者 https://www.devze.com 2023-02-09 11:38 出处:网络
开发者_运维知识库What does this mean? var settings = { \"column-1\" : [\"block-1\"], \"column-2\" : [\"block-2\"]

开发者_运维知识库What does this mean?

var settings = {
    "column-1" : ["block-1"], 
    "column-2" : ["block-2"]
};


It means one should [likely] read a tutorial/book on JavaScript before asking questions like this on SO ;-) (Explaining what "it means" will likely have not much "practical meaning" by itself.)

Like Eloquent JavaScript: A Modern Introduction to Programming

I believe the exact construct/term that is being sought is "object literals" -- {...} is for objects and [...] is for arrays.

Happy coding.


This will create a new object and store it in the settings variable.

The object is created by an Object literal and consist out of two propertys (column-1 and column-2) which are both assigned an Array with a single String value.


It defines an object containing two properties (column-1 and column-2) which both contain arrays which both contain a single value (block-1 an block-2).

Due to the - in the property name it will be impossible to access them using the object.property syntax so you'll have to use the array syntax: object['property']


Initialized a variable named settings and assigned the value {"column-1": ["block"], "column-2": ["block-2"]}, which is an object, to the settings.

0

精彩评论

暂无评论...
验证码 换一张
取 消