Inheritance using Object.Create
How can we use Object.Create in order to implement complex Prototype chain?
Inheritance using Object.Create
How can we use Object.Create in order to implement complex Prototype chain?
consider we have a prototype here and want to create another ; That inherits from the first Prototype:
const FirstPrototype={
init(fname,year){
this.fname=fname;
this.year=year;
},
calcAge(){
console.log(`${new Date().getFullYear()-this.year}`)
}
for inheritance there are 2 other ways one of them is using ES6 Classes that you are overwhelmed by faking classes by some keywords such as “extends , constructor , new” while in this method you just need to write:
const SecondPrototype=Object.create(FirstPrototype);
and now “SecondProtoype” inherits from “FirstPrototype”
const person=Object.Create(SecondPrototype);
person.init('ali',2010)
person inherits from SecondPrototype that inherits from FirstPrototype, this is called “Prototype Chain” now whatever can be found in FirstPrototype is inherited by person that is child of SecondPrototype

Now we want to add an init to SecondPrototype, this prototype is gonna have a new argument like course in addition to previous ones(name , year) and as we want to implement inheritance then we have to call init from FirstPrototype and then specify course:
const SecondPrototype=Object.create(FirstPrototype);
SecondPrototype.init=function(fname,year,course){
FirstPrototype.init.call(this,fname,year);
this.course=course;
}
now there will be a tiny differ for person, Now it will take course item as an init argument:
const person=Object.Create(SecondPrototype);
person.init('ali',2010,'Civil Engineer')

As it is shown the first parent for person is SecondPrototype that consist of init(fname,year,course) method with 3 arguments while it is inherited from the FirstPrototype that has 2 methods:clacAge() and init(fname,year) with 2 arguments
This is exactly the prototype chain that we saw earlirer and as it was mentioned it is really straight way of doing that cuz there are just some object that are linked together; Other wise ES6 classes are the most used way in real world and modern Javascript
메타데이터
- post_id
- 31bc106a8237
- slug
- inheritance-using-object-create-31bc106a8237
- url
- https://medium.com/@peymanfazeli/inheritance-using-object-create-31bc106a8237
- canonical_url
- https://medium.com/@peymanfazeli/inheritance-using-object-create-31bc106a8237
- author_url
- https://medium.com/@peymanfazeli
- status
- ok
- fetched_at
- 2026-07-13 06:23:13