JavaScript has undergone several incarnations during its life. These transformations have made it possible to modify and fine-tune the object creation and manipulation process. Besides the usual way to create objects with constructor functions and to assign prototypes to those functions, you can directly create objects from a prototype, define properties with the desired descriptors, and also control the enumerability or configurability of the properties.
The functions that are used for this purpose are situated on the Object constructor. For example, in order to create an object from an arbitrary prototype, you can use the Object.create function. Here is a simple example:
const dog = {
bark() {
console.log("Woof-woof!");
},
};
let pluto = Object.create(dog);
pluto.bark();
This is a list of the functions used for object creation or manipulation that are accessible through Object:
create
assign
defineProperty
defineProperties
getPrototypeOf
setPrototypeOf
getOwnPropertyDescriptor
getOwnPropertyDescriptors
getOwnPropertyNames
getOwnPropertySymbols
is
seal
freeze
preventExtensions
isExtensible
isSealed
isFrozen
keys
entries
values
There are a few methods on Object.prototype that are related to these tasks:
hasOwnProperty
isPrototypeOf
propertyIsEnumerable
The following property and methods on Object.prototype are deprecated and should not be used:
__proto__
__defineGetter__
__defineSetter__
__lookupGetter__
__lookupSetter__
Evidently, each of the functions that were listed in this post are very important and need extensive coverage. I hope to start a series of posts for explaining these functions.