We present another article focusing on understanding the concept of creating objects using Object.create. The article will discuss the advantages and disadvantages of using “Object.create” to clone objects. Let’s take a look at this function in detail.

What is Object.create?

Object.create can be used to create a new object from an existing object. When we create an object using Object.create, an empty object is created, and the “proto” object is mapped to the copied object.
When the “proto” attribute matches the object to be copied, it creates a chained structure that makes the properties and functions of the old object available to the newly created object.
Let’s look at the following using an example.

var empDetails = 
{
  name: "Ramesh Kumar",
  age: 40,
  designation: "Web Developer",
  contactDetails: "+91-9988776655"
}

var newEmpObject  =  Object.create(userDetails);

In the above example, we can see that we are trying to create a new Object using Object.create. A simple Object “empDetails” is passed to the same function. Let’s look for the debugger to look for the Object structure of new Object that is created out of this Execution.

CreateObject - https://codeconfig.in

While debugging we can observe that “newEmpObject” points out to an empty Object that contains internal “__proto__” property which maps to the “empDetails” object that is passed as a parameter to the “Object.create”.

Leave a Reply

Your email address will not be published. Required fields are marked *

Explore More

How to Center a Popup Window on Screen

JavaScript window.open() method is used to open a popup window. This popup window will be placed in the center of the screen. This example creates the pop-up window without placing it into

How to hide URL in the popup window opened using window.open

If you are using below code to open a popup window in your web page, then address must be appearing in you pop up window and f you want to

window.showModalDialog is deprecated in Edge and Chrome

If you have a website being compatible with Edge/Chrome and in past it was only compatible with IE 11 and if you are using window.showModalDailog in your JavaScript code, then