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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:43:58+00:00 2026-05-13T17:43:58+00:00

I am horrible at debugging and am totally confused as to why this won’t

  • 0

I am horrible at debugging and am totally confused as to why this won’t work. Here is my situation:

I wrote a function to open several links into tabs and then perform a very simple operation on them. It wasn’t working as I had anticipated so I rewrote it to just open one one link into one tab, which worked. This is what I have (simplified):

links=arrayFromGetElemenetsCall;
if(condition){
  theNewWindow=window.open(links[0]);
}
setTimeout("myFunction(theNewWindow)",5000);
}

function myFuntion(bob){
  bob.doStuff();
}

When I attempt to open more than one tab and save the window references into an array for future use I get an error. This is the simplified code for multiple windows:

var theArray=new Array();
links=arrayFromGetElemenetsCall;
for(conditions){
  if(condition){
    theArray[i]=window.open(links[i]);
  }
}
setTimeout("myFunction(theArray[0])",5000);}

function myFuntion(bob){
  bob.doStuff();
}

Which does not work. i get “Error: theArray is not defined” if and only if it is written into the setTimeout function. I have tried passing the entire array and then looping in myFunction as well as calling .doStuff() on bob[0].

What is it that i’m not seeing here?

  • 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-13T17:43:59+00:00Added an answer on May 13, 2026 at 5:43 pm

    Yikes. First of all, get out of the habit of passing strings as the first argument to setTimeout and setInterval. setTimeout will implicitly use eval to execute that string, and eval is evil.

    In this case, the secret eval is also the cause of your logical error. The snippet isn’t enough to precisely diagnose your problem, but basically in the eval scope, theArray is not defined. A rewrite to use a closure is a possible approach:

    setTimeout(function(obj){
        return function(){
            myFunction(obj);
        }
    }(theArray[0]), 5000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a horrible time getting this thing to work at all. I've spent
I am having a horrible time trying to get this to work. I have
I have this horrible habit of typing the below and not catching it until
I'm horrible with regex but i'm trying to figure out how an import function
Whilst working on some generally horrible Javascript code this morning, I came across the
I ended up with this horrible code below, I can't get a better result
my javascript is horrible so I'm not sure if this is as straight forward
That's a horrible title, sorry. Here's the scenario: WCF Service uses LINQ to get
as i said i get this horrible error i dont really know what to
The title is horrible, i know; I'm terrible at titles on SO here. I'm

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.