
JavaScript Basics: Object.getPrototypeOf and Object.setPrototypeOf
These functions, as is evident from their names, enable you to get and set the prototype of an object. In light of the availability of these functions, the use of the __proto__ property is generally discouraged.
Here is an example:
let objA = {};
let objB = {};
Object.setPrototypeOf(objA, objB);
Object.getPrototypeOf(objA) === objB; // true
The prototype of an object can be null. So you can assign null as the prototype of an object.
It should be noted that many JavaScript engines perform optimizations based on the value of [[prototype]] internal property. Changing the prototype with Object.setPrototypeOf will have adverse effects on those optimizations even after the prototype has been set. Therefore, in cases where performance is very important, the use of Object.create is more efficient than changing the prototype of an object with Object.setPrototypeOf.
Related Posts
Leave JavaScript Basics: Object.getPrototypeOf and Object.setPrototypeOf to:
Read more #javascript posts
Best Posts From ghasemkiani
We have not curated any of ghasemkiani's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From ghasemkiani
- Merging PDF Files with Java
- Happy Iranian New Year
- Stephen Hawking, one of the greatest physicists of our time, dies at 76
- Using Scoped NPM Packages
- Optimistic Typing in Nashorn
- JavaScript Basics: Reflect.apply
- JavaScript Basics: Reflect.construct
- JavaScript Basics: Reflect
- New Horizons Broke the Record of the “Pale Blue Dot” Picture
- JavaScript Basics: Object.freeze and Object.isFrozen
- JavaScript Basics: Object.seal and Object.isSealed
- JavaScript Basics: Object.preventExtensions and Object.isExtensible
- JavaScript Basics: Object.prototype.hasOwnProperty
- JavaScript Basics: Object.is
- JavaScript Basics: Object.keys, Object.values, and Object.entries
- What Is Success and How Do You Define It?
- Steemit Reached 700,000 Members
- JavaScript Basics: Object.getPrototypeOf and Object.setPrototypeOf
- JavaScript Basics: Object.assign
- JavaScript Basics: Object.create