JS: Object Overview
What is JavaScript Object
A JavaScript Object is a collection of key-value pairs.
e.g. {a:1, b:2}.
Each key/value pair is called a
Property
.
Special Object and Data Object
JavaScript objects can be categorized into 2 kinds:
- Object Object. (aka data object) → collection of key value pairs. e.g.
{a:1, b:2} - Specialized Object → special purpose and may have internal data. For example, function, date, regex, etc, are specialized objects. They have special properties and behaviors. But they still have the feature of holding key-value pairs.
〔see Object Type〕
Prototype of an Object (Parent)
- Each object MAY have ONE parent object. This object is call its prototype.
- The chain of parents is called Prototype Chain. The significance of Prototype Chain is how object's properties are looked up: When a property is accessed, JavaScript will go up the parent object or parent of parent etc to look for the property. (this is called inheritance.)
this is called Prototype-Based Object System
IsExtensible
Each object has a special true/false value attached called the [[isExtensible]] internal slot. It specifies whether new properties can be added to the object.
〔see Prevent Adding Property〕
Standard Object, Hosted Object, User-Created Object
It is useful to distinguish objects by where they came from. We have the following sources:
- Standard Object
- Objects from the JavaScript language. e.g. arrays, functions, dates, regex, etc. 〔see JavaScript Object Reference〕
- Hosted Object
-
Objects from the hosting environment. e.g. in Browser, there's
Browser's Window Object. In deno, there is
denoobject, with properties such as version etc. - User-defined Object (Data Object)
-
User defined. e.g.
let x = {a:1, b:2}.
Create Object
JavaScript Object Property Overview
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: Prototype Tree
- JS: Dot Notation and Prototype Chain
- JS: Create Object
- JS: Object Literal Expression
- JS: Object.create
- JS: Object Literal Expression vs Object.Create
- JS: Create Object with Parent X
- JS: Prevent Adding Property
- JS: Deep Copy Array or Object 📜
- JS: Test Equality of Array and Object by Content 📜
- JS: Add Method to Prototype
- JS: Object (class)
- JS: Object Constructor
- JS: Object.prototype