Why is my JavaScript function sometimes “not defined”?

后端 未结 13 1889
逝去的感伤
逝去的感伤 2020-12-24 01:18

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 g

13条回答
  •  萌比男神i
    2020-12-24 02:06

    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.

提交回复
热议问题