Why is my JavaScript function sometimes “not defined”?

后端 未结 13 1876
逝去的感伤
逝去的感伤 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条回答
  •  [愿得一人]
    2020-12-24 01:51

    I'm afraid, when you add a new method to a Function class (by prtotyping), you are actually adding it to all declared functions, AS WELL AS to your copyArray(). In result your copyArray() function gets recursivelly self-referenced. I.e. there should exist copyArray().bind() method, which is calling itself.

    In this case some browsers might prevent you from creating such reference loops and fire "function not defined" error.

    Inline code would be better solution in such case.

提交回复
热议问题