Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript and __proto__ - what browsers use it?

What web browsers use the __proto__? Mozilla states that:

Note that __proto__ may not be available in JavaScript versions other than that in Mozilla.

like image 326
Tower Avatar asked Jun 21 '10 07:06

Tower


People also ask

What is the use of __ proto __ in JavaScript?

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 prototype and __ proto __ in JavaScript?

prototype is a property of a Function object. It is the prototype of objects constructed by that function. __proto__ is an internal property of an object, pointing to its prototype. Current standards provide an equivalent Object.

What is prototype in JavaScript with example?

In JavaScript, every function and object has a property named prototype by default. For example, function Person () { this.name = 'John', this. age = 23 } const person = new Person(); // checking the prototype value console.

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.


3 Answers

Click here for your answer.

Details

The most general way would be to test this page in different browsers:

<html>
  <head>
    <script type="text/javascript">
      function a() {}
      if ( (new a).__proto__ === a.prototype )
          alert('supported');
    </script>

  </head>
</html>

It alerts if a browser supports __proto__. I've submitted it to browsershots.org, which will create screenshots of the page in many different browsers. Thus, you should see--by means of the alert message--which browser does support it.

like image 141
Charan Giri Avatar answered Sep 20 '22 06:09

Charan Giri


The Browser Security Handbook has a table showing which browsers expose __proto__.

Currently, those browsers are:

  • Firefox 2
  • Firefox 3
  • Safari
  • Chrome
  • Android

Those excluded:

  • IE 6, 7, 8
  • Opera
like image 31
strager Avatar answered Sep 19 '22 06:09

strager


The end of the sentence you posted is See below for workarounds., where there is a discussion on an alternative method extends() that uses super.prototype:

function extend(child, super){  
  for (var property in super.prototype) {  
    if (typeof child.prototype[property] == "undefined")  
      child.prototype[property] = super.prototype[property];  
  }  
  return child;  
}
like image 33
Oded Avatar answered Sep 18 '22 06:09

Oded