Creating JS objects that has no prototype

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)

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.

Until next time, think, learn, create,repeat!

About the Author

Leave a Reply

Your email address will not be published.

You may also like these