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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:11:40+00:00 2026-05-10T17:11:40+00:00

I call my JavaScript function. Why do I sometimes get the error ‘myFunction is

  • 0

I call my JavaScript function. Why do I sometimes get the error ‘myFunction is not defined’ when it is defined?

For example. I’ll occasionally get ‘copyArray is not defined’ even in this example:

function copyArray( pa ) {     var la = [];     for (var i=0; i < pa.length; i++)         la.push( pa[i] );     return la; }  Function.prototype.bind = function( po ) {     var __method = this;     var __args = [];      // Sometimes errors -- in practice I inline the function as a workaround.     __args = copyArray( arguments );      return function() {         /* bind logic omitted for brevity */     } } 

As you can see, copyArray is defined right there, so this can’t be about the order in which script files load.

I’ve been getting this in situations that are harder to work around, where the calling function is located in another file that should be loaded after the called function. But this was the simplest case I could present, and appears to be the same problem.

It doesn’t happen 100% of the time, so I do suspect some kind of load-timing-related problem. But I have no idea what.

@Hojou: That’s part of the problem. The function in which I’m now getting this error is itself my addLoadEvent, which is basically a standard version of the common library function.

@James: I understand that, and there is no syntax error in the function. When that is the case, the syntax error is reported as well. In this case, I am getting only the ‘not defined’ error.

@David: The script in this case resides in an external file that is referenced using the normal <script src=’file.js’></script> method in the page’s head section.

@Douglas: Interesting idea, but if this were the case, how could we ever call a user-defined function with confidence? In any event, I tried this and it didn’t work.

@sk: This technique has been tested across browsers and is basically copied from the Prototype library.

  • 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. 2026-05-10T17:11:41+00:00Added an answer on May 10, 2026 at 5:11 pm

    It shouldn’t be possible for this to happen if you’re just including the scripts on the page.

    The ‘copyArray’ function should always be available when the JavaScript code starts executing no matter if it is declared before or after it — unless you’re loading the JavaScript files in dynamically with a dependency library. There are all sorts of problems with timing if that’s the case.

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

Sidebar

Ask A Question

Stats

  • Questions 135k
  • Answers 135k
  • 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 You can perfectly well connect to databases over TCP/IP as… May 12, 2026 at 6:54 am
  • Editorial Team
    Editorial Team added an answer Probability of winning is probability of not losing all three:… May 12, 2026 at 6:54 am
  • Editorial Team
    Editorial Team added an answer MSDN MSMVPS C# Corner If you would like to get… May 12, 2026 at 6:54 am

Related Questions

I call my JavaScript function. Why do I sometimes get the error 'myFunction is
I have a login form which appears at the top of all of my
I know there is a lot of similar questions are tons of great answers
I've just started looking at JQuery. I don't have any AJAX in my web
I'm trying to create a small Javascript framework that I can use in my

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.