Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

__proto__ VS. prototype in JavaScript

This figure again shows that every object has a prototype. Constructor function Foo also has its own __proto__ which is Function.prototype, and which in turn also references via its __proto__ property again to the Object.prototype. Thus, repeat, Foo.prototype is just an explicit property of Foo which refers to the prototype of b and c objects.

var b = new Foo(20); var c = new Foo(30); 

What are the differences between __proto__ and prototype?

enter image description here

The figure was taken from dmitrysoshnikov.com.

Note: there is now a 2nd edition (2017) to the above 2010 article.

like image 499
0x90 Avatar asked Mar 31 '12 21:03

0x90


People also ask

What is __ proto __ JavaScript?

__proto__ is a way to inherit properties from an object in JavaScript. __proto__ a property of Object. prototype is an accessor property that exposes the [[Prototype]] of the object through which it is accessed. POSTly is a web-based API tool that allows for fast testing of your APIs (REST, GraphQL).

What is __ proto __ and [[ prototype ]]?

Proto: It is an actual object that provides a way inherit to inherit properties from JavaScript with the help of an object which is created with new. Every object with behavior associated has internal property [[prototype]]. Syntax: Object.__proto__ = value. Example: Javascript.

What is the use of __ proto __?

The __proto__ getter function exposes the value of the internal [[Prototype]] of an object. For objects created using an object literal, this value is Object. prototype . For objects created using array literals, this value is Array.

What is Dunder proto?

dunder proto === __proto__ Every object in JS has this property. It points back to the prototype object of the constructor function that created that object.


1 Answers

__proto__ is the actual object that is used in the lookup chain to resolve methods, etc. prototype is the object that is used to build __proto__ when you create an object with new:

( new Foo ).__proto__ === Foo.prototype; ( new Foo ).prototype === undefined; 
like image 133
Nobody Avatar answered Sep 19 '22 04:09

Nobody