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 6012717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:26:40+00:00 2026-05-23T02:26:40+00:00

I was browsing MDC about new functions added to Object. One of them, Object.preventExtensions

  • 0

I was browsing MDC about new functions added to Object. One of them, Object.preventExtensions, is said to prevent mutations to the object’s prototype, which can be obtained by using Object.getPrototypeOf or __proto__.

On Chrome, however, it seems to simply allow mutations to the object’s prototype. This can be confirmed by just executing the code on the relevant page:

// EXTENSION (only works in engines supporting __proto__
// (which is deprecated. Use Object.getPrototypeOf instead)):
// A non-extensible object's prototype is immutable.

var fixed = Object.preventExtensions({});
fixed.__proto__ = { oh: "hai" }; // throws a TypeError

I don’t get this TypeError, and fixed.__proto__.oh === 'hai', so it has been set even though it should have been disallowed. I can also add it when coding like Object.getPrototypeOf(fixed).oh = 'hai'.

Does this mean Chrome has a different interpretation of this function? How can one prevent extensions to an object’s prototype (in Chrome)?

  • 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-05-23T02:26:41+00:00Added an answer on May 23, 2026 at 2:26 am

    Nope, Chrome and Mozilla both implement the standards part of the spec the same. Read carefully:

    Object.preventExtensions only prevents
    addition of own properties. Properties
    can still be added to the object
    prototype.

    Everything to do with .__proto__ is non-standard, and Chrome can implement that differently. You showed only that Chrome implements details with .__proto__ differently, and in my opinion, more intuitively: The spec says that the prototype is still extensible, so it makes sense that you should still be able to mutate it. The question then becomes why did Mozilla implement it that way?

    For example, the following code works the same on both Chrome and FF:

    var fixed = Object.preventExtensions({});
    Object.getPrototypeOf(fixed).p = 99;
    fixed.p; // 99
    

    Clearly the prototype is still mutable. That makes sense with Chrome’s implementation of .__proto__.

    So to prevent extensions of a prototype, do so separately:

    var fixed = Object.preventExtensions({});
    Object.preventExtensions(Object.getPrototypeOf(fixed));
    Object.getPrototypeOf(fixed).p = 99; // TypeError: Can't add property p, object is not extensible
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Browsing the Internet, I found the new Ample SDK JavaScript framework. From their about
I was browsing through posts about Play! framework and came across some posts which
Is browsing speed depends on browser (like IE,firefox)? If it depends on browser which
While browsing I came across this blog post about using the Wikipedia API from
While browsing the MSDN documentations on Equals overrides, one point grabbed my attention. On
I'm browsing some news sites and most of them have the option of posting
Browsing the ruleby source code, I noticed that they were calling Container(:and) , which
I was just browsing some questions when I stumbled upon this one . I
While browsing through gcc's current implementation of new C++11 headers, I stumbled upon "......"
When browsing the Add-ons Manager, about:addons, in Firefox 4, the toolbars and urlbar are

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.