JavaScript: 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 (for example, function f(params) {body}
) or create a array (for example, ar = [7,2,4]
), you are also creating objects. [see Understand JS Array]
JavaScript Object and Inheritance
- Object Basics
- Object Overview
- Object Type
- Test If a Value is Object Type π
- Find Object's Type
- Prototype and Inheritance
- Prototype Chain
- Is in Prototype Chain?
- Get/Set Parent
- Show Parent Chain π
- Create Object
- Object Literal Expr
- Create Object + Parent
- Prevent Adding Property
- Clone Object π
- Test Object Equality π
- Add Method to Prototype