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

Blogger has this new fancy theme that I see a lot of people using,
I see a lot of people using django with tornado using WSGIContainer. Does this
I see a lot of people specify them like this. protected $myVar; protected $mySecondVar;
I see a lot of people are using code under viewDidLoad to be able
I see a lot of people in blog posts and here on SO either
I see a lot of the word 'expressiveness' when people want to stress one
I see a lot of this: 06-19 17:29:11.911: DEBUG/dalvikvm(10028): GC_FOR_MALLOC freed 729K, 54% free
OK I see a lot of people asking about passing other values, URLS, random
I see a lot of people with Django apps that have image uploads are
I see lot of new machines and laptops now having 64 bit hardware and

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.