Creating JS objects that has no prototype

Taslan Graham - Nov 17 '20 - - Dev Community

We know that All JavaScript objects inherit properties and methods from a prototype.

For example:
Date objects inherit from Date.prototype
Array objects inherit from Array.prototype

What if you want to create an Object that does not have a prototype?
Here's a neat little way to do it:

const blankObject = Object.create(null)
Enter fullscreen mode Exit fullscreen mode

When creating objects using Object.create(), we can pass an object which will be used as the prototype for the newly created object. Alternatively, we can pass null which will result in an object being created without a prototype.

I only came across this recently. I think it's pretty cool and I may find some use for it.

. . . . . . . . . . . . . . . . .
Terabox Video Player