In standard OO, as defined by UML, and instantiated, e.g., by Java and C#, there is a certain concept of objects as instances of classes. What's the difference between this classical concept of objects and a JavaScript object?
JavaScript objects are different from classical OO/UML (C++/Java/C# etc.) objects. In particular, they need not instantiate a class. And they can have their own (instance-level) methods in the form of method slots, so they do not only have (ordinary) property slots, but also method slots. In addition they may also have key-value slots. So, they may have three different kinds of slots, while classical objects (called "instance specifications" in UML) only have property slots.
JavaScript objects can be used in many different ways for different purposes. Here are five different use cases for, or possible meanings of, JavaScript objects:
var myRecord = { firstName:"Tom", lastName:"Smith", age:26}
var numeral2number = { "one":"1", "two":"2", "three":"3"}
which associates the value "1" with the key "one", "2" with "two", etc. A key need not be a valid JavaScript identifier, but can be any kind of string (e.g. it may contain blank spaces).
var person1 = {
lastName: "Smith",
firstName: "Tom",
getInitials: function () {
return this.firstName.charAt(0) + this.lastName.charAt(0);
}
};
var myApp = { model:{}, view:{}, ctrl:{} };
o
that instantiates a class defined by a JavaScript constructor function C
is created with the expression var o = new C(...)
The type/class of such a typed object can be retrieved with the introspective expression
o.constructor.name // returns "C"
See my JavaScript Summary for more on JavaScript objects.