简体   繁体   中英

Javascript variables of class type

I am seeing a piece of code . Its a . js file . I see that this file has the following kind of variable declared

var abc = {};
abc.Version="xxx";
abc.path="yyyy"

In other words the variable is used like a class . In saw the Javascript tutorials : here & here . But i see no mention of a class type variable .

What is it ? Wondering why isnt it mentioned in these websites .

It is an object literal. What you're seeing on lines #2/3 are properties and associated values being dynamically added to it.

The variable abc is an object, but there are no classes in JS. JS uses prototypical objects, not classical objects, which is what languages like Java and C++ do.

With JS, you can declare an object like your first line of code above, and then dynamically declare properties of that object on the fly, as is the case in lines 2 and 3 of your code above.

它们是您对象的属性

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM