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

  • Home
  • SEARCH
  • 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 5985643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:33:34+00:00 2026-05-22T22:33:34+00:00

I see a lot of people doing this Object.prototype.foo = ‘HALLO’; var hash =

  • 0

I see a lot of people doing this

Object.prototype.foo = 'HALLO';
var hash = {baz: 'quuz'};

for ( var v in hash ) {
  // Do not print property `foo`
  if ( hash.hasOwnProperty(v) ) {
    console.log( v + " is a hash property" );
  }
}

My question is rather than testing .hasOwnProperty each time you wish to use an Object as a hash why not just set the .__proto__ to null on the object? †

hash.prototype = null;
hash.__proto__ = null;

for ( var v in hash ) {
  // Do not print property `foo`
  console.log( v + " is a hash property" );
}

It has been brought to my attention that __proto__ is nonstandard. That still doesn’t answer the question though…

var foo = Object.create(null);
Object.getPrototypeOf(foo);

This can’t be an original question, but I can’t find anything about changing __proto__ to null to eliminate the drawbacks of having to check for inheritance? What’s wrong with this approach, seems to make code faster (don’t have to check properties of Object) and cleaner?

† And the .prototype property if you plan on making future children of it.

  • 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-22T22:33:34+00:00Added an answer on May 22, 2026 at 10:33 pm

    There’s nothing inherently wrong with creating [[Prototype]]’less objects to avoid hasOwnProperty-based checks during “hash” enumeration.

    In fact, some of the libraries I know (fuse.js being one of them, IIRC) do exactly that.

    Now on to the practical problems:

    1. __proto__ is non-standard. See my compat. table. Notice how IE doesn’t support __proto__ up until and including IE9. Of course, IE9 supports Object.create and so it becomes possible to create [[Prototype]]’less object with Object.create(null) but that still leaves IE6, IE7 and IE8. Oh and Opera <10.10, as you can see (which doesn’t support Object.create). Fortunately, existence (and functionality) of __proto__ can be easily feature tested, which is why non-supporting browsers can be made to take hasOwnProperty-based or some other route.

    2. Removing [[Prototype]] from the object “removes” all of the Object.prototype.* methods. Naturally. So, for example, myHash.toString() (or even myHash + '') will now error out unless you give that hash toString method. Ditto for valueOf, hasOwnProperty, and all the other Object.prototype.* methods. This isn’t big deal, of course, as you can always define those methods (and probably should — to make them specialized for hash usage) but it’s more work nevertheless.

    As far not finding anything about this approach… I was talking about it at least 2 years ago 🙂 — http://groups.google.com/group/comp.lang.javascript/msg/9451c45080b5e9f0 (likely earlier too, but can’t find any other posts on comp.lang.javascript at the moment). There are more interesting findings about browsers’ behavior with __proto__ === null in that thread. Check it out.

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

Sidebar

Related Questions

It seems like a lot of people struggle with date/time issues in PHP, and
There is a lot of (older) related data spread over many tables in our
(A while back I read this great post: http://aaronlongwell.com/2009/06/the-ruby-on-rails-cms-dilemma.html , discussing the Rails CMS
I'm doing a Java project where I have to make a text similarity program.
I have a project that uses the normal Maven structure, e.g. module \ src
I have a program, it starts in a winmain which calls run_game in its
I have made an app that paints FFT to the screen realtime (from mic).
Update: It's not really necessary to remove added scripts considering once they run you
I've inherited a medium sized project in which the main (batch) program is fed
When I first got into databases I was using SQL Server. I got into

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.