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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:45:05+00:00 2026-05-13T14:45:05+00:00

I was making a function to convert all dates in an object to strings

  • 0

I was making a function to convert all dates in an object to strings and when I used the following function I got a error in FF “too much recursion”. (It also fails in IE and chrome)

    function datesToString(obj) {
        if (obj instanceof Object) {
            if (obj instanceof Date) {
                obj = "this part does not matter";
            } else {
                for (var key in obj) { obj[key] = datesToString(obj[key]); }
            }
        }
        return obj;
    }

but when I changed it to use typeof it worked fine?

    function datesToString(obj) {
        if (obj  && typeof obj == "object") {
            if (obj instanceof Date) {
                obj = "this part does not matter";
            } else {
                for (var key in obj) { obj[key] = datesToString(obj[key]); }
            }
        }
        return obj;
    }

It should be the same amount of recursion. Am I missing something? Why am I getting an error with the first example but not the second?

Update:
here is an example of the object I was using (in json form)

Contact = {
    "LContactID": "00000000-0000-0000-0000-000000000000",
    "CellPhone": "",
    "HomePhone": "4564564560",
    "OtherPhone": "",
    "BirthDate": new Date(-62135575200000),
    "SSN": "456456456",
    "HowToContact": 1,
    "ContactType": 3,
    "Address1": "123 test",
    "Address2": "apt. 1",
    "City": "Valparaiso",
    "State": "IN",
    "Zip": "46383",
    "FullAddress": "123 test, apt. 1",
    "BuilderID": "",
    "FullAddressWithCityState": "123 test\r\napt. 1\r\nValparaiso, IN 46383",
    "WorkHours": "9-5",
    "ContactTime": "",
    "ContactMethod": "???",
    "IsMilitaryOrSelfEmployed": false,
    "AlternateContactName": "",
    "AlternateContactPhone": "",
    "ContactID": "00000000-0000-0000-0000-000000000000",
    "Password": null,
    "FirstName": "updatetest",
    "MiddleName": null,
    "LastName": "test_",
    "Suffix": null,
    "EmailAddress": null,
    "EmailAddressAlternate": null,
    "WorkPhone": "6546546540",
    "WorkPhoneExt": null,
    "CreatedOn": new Date(1263597309000),
    "CreatedOnOverride": new Date(-62135575200000),
    "ModifiedOn": new Date(1264014749000),
    "SCRep": "",
    "HBCRep": "",
    "PPPRep": "",
    "DPSRep": "",
    "DRSRep": "",
    "RDRep": "",
    "OwnerID": "00000000-0000-0000-0000-000000000000",
    "FullName": "updatetest test_",
    "ImportID": 0,
    "IncludeEmail": false,
    "PreferredLanguage": 1,
    "CarbonCopyList": [],
    "HearAboutUs": 5,
    "HearAboutUsOther": "",
    "init": function() { },
    "update": function() { },
    "load": function() { }
}

It looks like when I remove the method parameters (init,update and load) it works with the instanceof example.

UPDATE: This is a ASP.Net ScriptManager problem it turns out. Sorry for not including the fact that I was working with an ASP.Net website.The ASP.Net ScriptManager prototypes methods to Function which causes an infinity loop when doing a recursive for in loop on a function.

  • 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-13T14:45:06+00:00Added an answer on May 13, 2026 at 2:45 pm

    (First, let me say that I tried your code on FF 3.5.7 and it didn’t run into an infinite recursion. maybe you used a different input example?)

    Anyway, to answer your questions:

    (a) Why do you get an infinite recursion? Because an object may refer to itself. If o.f==o then calling your function on o will fire a subsequent call on o.f which is actually o and so on…

    (b) Why the difference between the two versions? obj instanceof Object checks if obj is an instance of Object or an instance of a subclass thereof. Given that every Javascript object inherits from Object then this condition is trivially true, and is thus meaningless. Net result is that the first if always succeeds. On the other hand typeof obj == "object" checks that obj is an instance of Object. This may be false, for example, if obj is an instance of String (at which case typeof obj yields String). Hence, the difference.

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

Sidebar

Ask A Question

Stats

  • Questions 378k
  • Answers 378k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try this regex instead: /:\w+/ \w matches any of a-z,… May 14, 2026 at 9:15 pm
  • Editorial Team
    Editorial Team added an answer There are two properties in UITableView, that are called delegate… May 14, 2026 at 9:15 pm
  • Editorial Team
    Editorial Team added an answer If LIMIT is 0 you will get an empty result… May 14, 2026 at 9:15 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.