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

后端 未结 5 2140
难免孤独
难免孤独 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:31

    you have put the call to the private method inside the constructor of the javascript class. in that point the functions are not yet initialized

    but if you initialize the object like so:

    var test = new MyObject(); 
    

    and then do this:

    test.myMethod();
    

    it will work.

提交回复
热议问题