reference types
Last updated 2 years ago
JS โฉ value โฉ object
an unordered collection of properties (name : value pairs).
inherits properties of another object, known as it's prototype.
any value that is not primitive is an object.
// creating objects {name: value} // object literal new Object() // `new` statement let obj = Object.create(prototype) // specify an object's prototype
synonyms๏ผ "hash", "hashtable", "dictionary", "associated array".
most common things to do with objects๏ผ
create objects.
access (get/set, delete / test / enumerate) their properties.
creating objects
object literal / new / Object.create()
accessing properties
property access expression
dot notation (.) / bracket notation []
optional chaining (?., ?.[]) / optional invocation ?.()
delete / test / enumerate properties
extending objects
Object.assign() - copies properties from other objects.
mixin
inheritance
prototype
prototype chain
converting objects
serializing objects - convert/restore object's state to/from string.
.toString() / .toLacaleString() - object -> string.
.valueOf() - object -> primitive (typically a number)
.toJSON() - a method expected by JSON.stringify()
use optional chaining (?., ?.[]) to safely acess object's members.
literal
event handler can be an object.
the import in import.meta is NOT an objectโ๏ธ
JS object is associated array.
ExploringJS โฉ 14. New OOP features besides classes
JavaScript: The Definitive Guide โฉ Ch. 6 Object
MDN โฉ JavaScript โฉ
JavaScript Guide โฉ Working with objects
built-in objects โฉ
Object
Function
Proxy
accessor property