Object.create vs Object.assign

The Object.create() method creates a new object, using an existing object as the prototype of the newly created object.

what does it means by “prototype of the newly created object” .

and what are the cases this is usefull?


You don’t show a link to what you are quoting so I can’t refer back to it, but here is an article about prototypes.

I took it from there but the question I asked is still not clear to me, thats why I asked here.

So from this source we can see the definition is:

Every object in JavaScript has a built-in property, which is called its prototype . The prototype is itself an object

I assume you understand what a property is.

And the reason for this prototype property is

Prototypes are the mechanism by which JavaScript objects inherit features from one another.

So the word “mechanism” here tells you that this is the method that JavaScript uses to implement the concept of inheritance.

I know the prototype intro and pretty much js ,
but the question I am having here, is what use-cases are possibly require this Object.create method to work on.

and how the use of Orignal or Existing object as the Prototype of the newly Created Object is helpful ?

what things we get to manipulate with the prototype.?

One use case of using create is to create a “static class”.
Basically it is a class that has no prototype of its own (similar to how the Object prototype class’s prototype is null).
This means that its assigned properties cannot be changed. This might be useful for preventing people who use it from changing it.

You can probably also use it if you ever need to create a certain type of class but didn’t want to get the default construction of it (because when you use create you can also set a different set of properties)

Longer discussion on this here Object.create() - JavaScript | MDN

so we can say that,
the object behaves like a front-face for its prototype,
and the prototypes behaves like the constructor to define more methods for further uses?

I don’t think I agree with this statement.

When you create any object in js, it automatically inherits properties and methods. Where does it get these from?
The prototype object.

By default you can create an object and call toString() on it for eg without ever explicitly defining it. And it works because of the inheritance created by the prototype property.

You can add your own property and method definitions to your custom class on top, but without the prototype there would be no inherited properties or methods available to you.

1 Like

Yeah I have been looking and trying some my own methods with proto
and It is really very clear to me now, and is exactly what you are telling,
got very clear understanding of it and thankful for your time and support.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.