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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:17:58+00:00 2026-05-18T23:17:58+00:00

I have a very odd problem with javascript. My code is rather long so

  • 0

I have a very odd problem with javascript. My code is rather long so here is an example of the structure and the problem:

var x = new function f() {
    this.id = "";
}

function g(obj) {
    if (x.id == "") {
        ...
        obj.firstChild.setAttribute("onclick", "javascript:o();");
        ...
        x.id = obj.id;
    } else if (x.id != obj.id) {
        ...
        x.id = "";
        g(obj);
    }
}

function o() {...
    if (something == something) {
        ...
    } else {
        ...
        x.id = ""; // if-statement of the g() function is called here?
    }
}

As you can see, the if-statement of the g() function is for some reason called or re-run upon x.id being changed. I simply cannot understand this, because they are not in the same scope, and changing a variable should under no circumstances trigger anything?

Any help would be greatly appreciated.

  • 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-18T23:17:59+00:00Added an answer on May 18, 2026 at 11:17 pm

    x.id = ""; // if-statement of the g() function is called here?

    If the code really is as you show it, that line of code will not generate a function call. The line is simply an assignment to the id property of x. The only way a function call could be triggered by your assigning to the id property of x would be if you were using a browser that supported property accessors (getters and setters), which is very unlikely (and there’s nothing in your code doing so).

    Something else would appear to be calling g in a loop of some kind, and so your changing the value makes the next call to g see the change. As Jonathon pointed out in his comment on the question, this could be something you’ve set up with setTimeout, or setInterval, or in an even handler (on mouse move, for instance), etc., but it’s nothing in the quoted code.


    Possibly off-topic:

    You have this line of code at the outset:

    var x = new function f() {
        this.id = "";
    }
    

    That code uses a “named function expression,” which should be valid but causes problems in some implemenations (IE, for instance). Split it up to get the desired result reliably cross-browser:

    var x = new f();
    function f() {
        this.id = "";
    }
    

    Off-topic:

    You don’t use the javascript: pseudo-protocol except on attributes that take a URI (like href on a elements). The onclick attribute does not take a URI, it takes JavaScript code, so change:

    obj.firstChild.setAttribute("onclick", "javascript:o();");
    

    to

    obj.firstChild.setAttribute("onclick", "o();");
    

    But, better yet, assign the handler directly:

    obj.firstChild.onclick = o;
    

    …or even consider using addEventListener or its IE-counterpart attachEvent instead.

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

Sidebar

Related Questions

This is my first question on S.O. I have a very odd problem. Below
I have a very odd problem. A class property is mysteriously reset between method
I have come across a very odd problem in C that I have never
Very odd problem as this is working perfectly on our old Classic ASP site.
This seems to be a very odd problem that I cannot figure out for
I have a rather confusing problem. I have a php file (http://example.com/delete.php) <?php session_start();
I have a rather confusing problem. I have a php file (http://example.com/delete.php) <?php session_start();
I've been experiencing this very odd problem lately in Heroku. I develop and test
I have having a very odd issue when utilizing this UIAlertView. When viewing a
I have an odd problem with the following: function loadTextbox(jsonUrl,divId){ $.getJSON(jsonUrl, function(json) { $('#'

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.