Javascript - How do you call a function inside a class from within that class?

后端 未结 5 2128
难免孤独
难免孤独 2021-02-18 13:25

I am trying to call the function MyMethod from within a object but none of the syntax below works. There must be a really obvious error below but I can\'t see it.



        
5条回答
  •  暖寄归人
    2021-02-18 13:42

    I'm pretty sure you can define methods anywhere in the file, even after you call them, but they way you are defining the method is the flaw.

    http://ejohn.org/apps/learn/#5

    Notice that if you define a variable with an anonymous function as it's value then you are not able to call the function by name (because it doesn't have one). Instead you should name it using the convention

    function nameOfTheFunction( arguments ) {
    ...
    }
    

    I found the following link will to be very useful:

    http://www.dustindiaz.com/javascript-function-declaration-ambiguity/

提交回复
热议问题