Object and Prototype - Aimanizales/Javascript_learning GitHub Wiki
1.1 The simplest object types
Object-like type (they have methods but they're immutable):
- Number (Object-like type)
- String (Object-like type)
- Boolean (Object-like type)
- null
- undefined
All other values are Objects.
1.2 Object
- It's a container of properties
name: value. - It's Mutable keyed collections.
- Class-free. (?)
- Can contain other objects.
- Arrays, functions, regexp are also objects.
- They are passed around by reference.
const anyObject = {
name: value
}
// name can be any string, even an empty string.
// value any JS value except undefined.
1.3 Prototype
- It's an "object's object".
- Feature of JS.
- It allows one object to inherit properties from another object.
- Can reduce object initialization time and memory consumption.
1.3.1 How to create an object and choose obj prototype
- Used only in retrieval.
- Some methods and operators
hasOwnProperty()to exclude prototype properties. delete toremove a property (only own ones).
1.3.2 Recommendations
- Global abatement: create a single global variable to reduce the probability of bad interactions with other apps, widgets or libraries.