Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7909131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:16:30+00:00 2026-06-03T12:16:30+00:00

Mozilla claimed it would remove __proto__ a while back (~2008) and it is still

  • 0

Mozilla claimed it would remove __proto__ a while back (~2008) and it is still in the browser. Is it still going to be deprecated? It works in Opera, (Safari I think) and Chrome as well. I don’t need to worry about IE so I would love to keep using it.

However, I don’t want my code to stop working one day, so on to my question:

__proto__ allows for dead simple inheritance:

a.__proto__ = {'a':'test'}

Is there anyway I can replicate this in a standards compliant way? I know there is functional inheritance, that’s ugly, and it over-complicates the fact that I just want to create a prototype chain. Just wondering if any wizards have solved this.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T12:16:34+00:00Added an answer on June 3, 2026 at 12:16 pm

    Note: It’s considered a bad practice to change the value of __proto__. Doing so is strongly discouraged by Brendan Eich, the creator of JavaScript, amongst others. In fact the __proto__ property has been removed entirely from a few JavaScript engines like Rhino. If you wish to know why then read the following comment by Brendan Eich.

    Update: Browsers are not going to remove the __proto__ property. In fact, ECMAScript Harmony has now standardized both the __proto__ property and the setPrototypeOf function. The __proto__ property is only supported for legacy reasons. You are strongly advised to use setPrototypeOf and getPrototypeOf instead of __proto__.

    Warning: Although setPrototypeOf is now a standard, you are still discouraged from using it because mutating the prototype of an object invariably kills optimizations and makes your code slower. In addition, the use of setPrototypeOf is usually an indication of poor quality code.


    You don’t need to worry about your existing code not working one day. The __proto__ property is here to stay.

    Now, for the question at hand. We want to do something similar to this in a standards compliant way:

    var a = {
        b: "ok"
    };
    
    a.__proto__ = {
        a: "test"
    };
    
    alert(a.a); // alerts test
    alert(a.b); // alerts ok
    

    Obviously you can’t use Object.create to achieve this end since we are not creating a new object. We are just trying to change the internal [[proto]] property of the given object. The problem is that it’s not possible to change the internal [[proto]] property of an object once it’s created (except via using __proto__ which we are trying to avoid).

    So to solve this problem I wrote a simple function (note that it works for all objects except for functions):

    function setPrototypeOf(obj, proto) {
        var result  = Object.create(proto);
        var names   = Object.getOwnPropertyNames(obj);
        var getProp = Object.getOwnPropertyDescriptor;
        var setProp = Object.defineProperty;
        var length  = names.length;
        var index   = 0;
    
        while (index < length) {
            var name = names[index++];
            setProp(result, name, getProp(obj, name));
        }
    
        return result;
    }
    

    So we can now change the prototype of any object after it’s created as follows (note that we are not actually changing the internal [[proto]] property of the object but instead creating a new object with the same properties as the given object and which inherits from the given prototype):

    var a = {
        b: "ok"
    };
    
    a = setPrototypeOf(a, {
        a: "test"
    });
    
    alert(a.a); // alerts test
    alert(a.b); // alerts ok
    <script>
    function setPrototypeOf(obj, proto) {
        var result  = Object.create(proto);
        var names   = Object.getOwnPropertyNames(obj);
        var getProp = Object.getOwnPropertyDescriptor;
        var setProp = Object.defineProperty;
        var length  = names.length;
        var index   = 0;
    
        while (index < length) {
            var name = names[index++];
            setProp(result, name, getProp(obj, name));
        }
    
        return result;
    }
    </script>

    Simple and efficient (and we didn’t use the __proto__ property).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Settings for the Mozilla Firefox browser my be changed by entering about:config in the
According to this Mozilla article on Ogg media , media works more seamlessly in
Is there a Firefox/Mozilla control for embedding the firefox browser in a C# .net
https://developer.mozilla.org/en/New_in_JavaScript_1.7 A lot of these new features are borrowed from Python, and would allow
I'm embedding Mozilla's SpiderMonkey in my application and would like to use its new
I want to use Mozilla Gecko as web browser instead default IE in C#.
How do mozilla addons or IE activeX plugin's handle browser page zoom ?
If you open up your mozilla Firefox web browser and turn on firebug to
I have set Mozilla Firefox as default browser and and MVC 2 web app
CSS box-shadow works on Mozilla, but not on Chrome. If I use the class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.