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!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: