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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:31:20+00:00 2026-05-14T05:31:20+00:00

In an article on yuiblog Douglas Crockford says that the for in statement will

  • 0

In an article on yuiblog Douglas Crockford says that the for in statement will iterate over the methods of an object. Why does the following code not produce [“a”, “b”, “c”, “d”, “toString”]? Aren’t .toString() and other methods members of my_obj?

Object.prototype.toString = function(){return 'abc'}
Object.prototype.d = 4;

my_obj = {
    'a':1,
    'b':2,
    'c':3
}

a = []
for (var key in my_obj) {
    a.push(key)
}

console.log(a) // prints ["a", "b", "c", "d"]
  • 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-14T05:31:20+00:00Added an answer on May 14, 2026 at 5:31 am

    All user defined properties are enumerable, including the properties inherited from prototype. The built-in native properties are not. toString() is one of them. See here https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Statements/For…in

    Edit: My interpretation of “However, the loop will iterate over all user-defined properties (including any which overwrite built-in properties)” is that the properties that are overwritten directly in the object become enumerable. Not the overwrite in the prototype itself. That means:

    var my_obj = {a: 1, b: 2, c: 3};
    my_obj.toString = function() {return 'abc';};
    
    a = []
    for (var key in my_obj) {
        a.push(key)
    }
    
    console.log(a) // prints ["a", "b", "c", "toString"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The article states the following: http://msdn.microsoft.com/en-us/library/dd799517.aspx Variance does not apply to delegate combination. That
This article says that you need to use resizable MemoryStreams when working with the
This article says If an object has a finalizer, it is not immediately removed
Article at http://leepoint.net/notes-java/algorithms/big-oh/bigoh.html says that Big O notation For accessing middle element in linked
This article about Java security says: Code in the Java library consults the Security
This article http://cobworks.ca/2010/04/19/why-android-market-has-no-games/ suggests that it does not, but I was hoping something might
This article on memory leaks emphasizes that having superfluous event listeners leads to memory
This article explains how to correct an exception that's often seen when switching an
This article on MSDN states that you can use as many try catch blocks
This article says: Every prime number can be expressed as 30k±1 , 30k±7 ,

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.