DEV Community

Cover image for Javascript Object #7
Asir-Sam
Asir-Sam

Posted on

Javascript Object #7

Welcome All,in the last post we've seen what is Prototype in Object.In Javascript every Object contains a Prototype property and it itself is an another Object and it contains many useful methods.
Now we are going to see about the Prototypal Linkage in Object,as from the last post we have seen that Javascript doesn't conatains classical inheritance instead it has Prototypal Inheritance in the Post we are Going to see about the How this Proto Inheritance is happening.

PROTOTYPAL INHERITANCE

Most of the People Don't know that Javascript has an inbuild Function called Object() most of the Novice developers think that it is Just an Object,but it is not an Object.while you console log this,

`typeof(Object)

output
'function'

`
Enter fullscreen mode Exit fullscreen mode

Pretty Confusing right, yeah may be at the beginning it will, as you been new to Javascript Prototype.

Javascipt also has an anonymous object and that can be referenced via Object.prototype.as you can see,

`console.log(Object.prototype);`
Enter fullscreen mode Exit fullscreen mode

Image description

the Object.prototype has some usefull properties like toString,_ valueOf_ and it also has some important property called constructor and it reference to and Object() function.this is how Javascript Object linking together for example,

`console.log(Object.prototype.constructor === Object); // true`
Enter fullscreen mode Exit fullscreen mode

as you can see both are same,

Let's visaulize this in more better way,assume circle as a Object() function and Square as an Object.let illustrate the relationship between them,

Image description

thus,this how they linked together.

Let's first define a Constructor Function,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6wjhwm9g3sf3ugj0ib05.png)
`function Person(name) {
    this.name = name;
}`
Enter fullscreen mode Exit fullscreen mode

In this Fuction,it accepts an argument called name and assign it to the name Property of this Object.

But do you know what's happening behind the scenes,the Javascirpt engine will create an Function Person and an anonymous Object.Like the Object() Function.Person function has a Prototype Property and it reference the anonymous Object and the Object has a constructor Property that holds the Person() function.

Image description

In addition,Javascript links the Person.prototype and Object.Prototype Object via the [Prototype],which is know as the Prototypal Linkage.This is called The Prototypal linkage in the Javascript

Image description

So for,we have seen how Prototypal Linkage is Happening in Javascirpt Object.In future Post we'll see how to methods are linking using the real time examples.

Please Support me by giving a reaction to this post,
If you've learned something.

Many Thanks for You Patience and Time,
Sam

Top comments (4)

Collapse
 
muzzammil194 profile image
Muzzammil Shaikh

That's is great I expected no one wrote article over it. Somehow I already used in the microservices real-time project of the experienced developer wrote logic he create class create function and object pass into the array of the other class and it's array pass in return type of the function and used function in another class and like array.prototype.constrctor after that I check whole code I got confused at that time when I started debug mode enable in node js and place breakpoint place on that line
array.prototype.constrctor
I realised that it's worked on runtime and it's very useful approch

Collapse
 
asir-sam profile image
Asir-Sam

Thank! Well i'm really curious to learn and develop microservices using Nodejs
Hope we will look very deep into it.

Collapse
 
muzzammil194 profile image
Muzzammil Shaikh

Have you write next artical for that scenario mention me and I'm curious for learn more about it

Collapse
 
asir-sam profile image
Asir-Sam

Yeah! Thank !
I will do further research and Update it