JS: Create Object
There are 3 common ways to create data object.
Object Literal Expression
{k1:v1, k2:v2 }
Most useful, when you want to use it as a set of key/value pairs for data.
〔see Object Literal Expression〕
Object.create()
Object.create()
Most powerful and flexible way to create object, because you can specify parent object, properties, property attributes, all in one function call.
〔see Object.create〕
Create Object by Operator “new”
new functionName()
complex behavior. It tries to be similar to Java's object oriented programing concepts, but the result is very complex. For some standard objects, such as Date, it's the only way to create it.
〔see Operator “new”〕
Note: remember that function and array are also objects. So, when you define a function (e.g. function f(params) {body}
) or create a array (e.g. ar = [7,2,4]
), you are also creating objects. 〔see Understand JS Array〕
JavaScript, Object and Inheritance
- JS: Object Tutorial
- JS: Object Overview
- JS: Object Type
- JS: Test is Object Type 🚀
- JS: Determine Type of Object
- JS: Prototype and Inheritance
- JS: Prototype Chain
- JS: Object.prototype.isPrototypeOf
- JS: Get Set Prototype
- JS: Show Prototype Chain 🚀
- JS: Create Object
- JS: Object Literal Expression
- JS: Create Object with Parent X
- JS: Prevent Adding Property
- JS: Deep Copy Object or Array 🚀
- JS: Test Object Equality 🚀
- JS: Add Method to Prototype
- JS: Object Object
- JS: Object Constructor
- JS: Object.prototype