Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is __proto__ useful?

Tags:

javascript

When is __proto__ useful?

A lot of browsers support it, but because not all do, programmers seem to be scared of using it. I've never seen it in any code (such as the libraries jQuery and backbone.js).

When is __proto__ useful? Is it just a geeky thing for completeness?

like image 707
Randomblue Avatar asked Sep 28 '11 20:09

Randomblue


People also ask

What is the use of __ proto __?

Description. 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.

What is __ proto __ in 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).

When should I use JavaScript prototype?

You should use prototypes if you wish to declare a "non-static" method of the object. var myObject = function () { }; myObject. prototype.

What is the point of prototypal inheritance?

Prototypical inheritance allows us to reuse the properties or methods from one JavaScript object to another through a reference pointer function.


2 Answers

__proto__ is deprecated and should not be used. Use Object.getPrototypeOf instead. See https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/Proto - But Opera supports __proto__ and not Object.getPrototypeOf, so beware.

That said, Object.getPrototypeOf is, like the name says, used to get the prototype of an object. I've never found this useful yet.

Edit 2012-02-06 Opera supports Object.getPrototypeOf as of 11.60.

like image 181
Tamzin Blake Avatar answered Oct 02 '22 19:10

Tamzin Blake


It is useful if you are going to modify an objects prototype and need to find out if it has been already modified.

Note that __proto__ is deprecated, instead you should is Object.getPrototypeOf.

MDN Documentation on proto

like image 28
amosrivera Avatar answered Oct 02 '22 18:10

amosrivera