DEV Community 👩‍💻👨‍💻

Cover image for JavaScript __proto__ and prototype
tkssharma
tkssharma

Posted on

JavaScript __proto__ and prototype

There are many explanation of proto and prototype, Have a look on what i have covered

prototype is a property of a Function object. It is the prototype of objects constructed by that function.

proto is internal property of an object, pointing to its prototype. Current standards provide an equivalent Object.getPrototypeOf(O) method, though de facto standard proto is quicker.

You can find instanceof relationships by comparing a function's prototype to an object's proto chain, and you can break these relationships by changing prototype.

function Point(x, y) {
    this.x = x;
    this.y = y;
}

var myPoint = new Point();

// the following are all true
myPoint.__proto__ == Point.prototype
myPoint.__proto__.__proto__ == Object.prototype
myPoint instanceof Point;
myPoint instanceof Object;
Enter fullscreen mode Exit fullscreen mode

Here Point is a constructor function, it builds an object (data structure) procedurally. myPoint is an object constructed by Point() so Point.prototype gets saved to myPoint.proto at that time.

https://www.youtube.com/watch?v=EhOGAPjbKEg&list=PLIGDNOJWiL19go98IKaQ4sqThyi2V67JG

Part1- https://www.youtube.com/watch?v=coh7OhK3O90&list=PLIGDNOJWiL19go98IKaQ4sqThyi2V67JG&index=9

Part-2 https://www.youtube.com/watch?v=OBpTuRIBD9M&list=PLIGDNOJWiL19go98IKaQ4sqThyi2V67JG&index=10

Top comments (0)

DEV

Thank you.

 
Thanks for visiting DEV, we’ve worked really hard to cultivate this great community and would love to have you join us. If you’d like to create an account, you can sign up here.