DEV Community

Cover image for Creating JS objects that has no prototype
Taslan Graham
Taslan Graham

Posted on

2 2

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)
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.

Top comments (2)

Collapse
 
bias profile image
Tobias Nickel

you asked it yourself,... why?

Collapse
 
taslangraham profile image
Taslan Graham

no reason in particular. Just found it interesting.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay