Uncaught TypeError: (intermediate value)(…) is not a function

前端 未结 7 1937
不思量自难忘°
不思量自难忘° 2020-12-02 10:42

Everything works fine when I wrote the js logic in a closure as a single js file, as:

(function(win){
   //main logic here
   win.expose1 = ....
   win.expos         


        
7条回答
  •  广开言路
    2020-12-02 11:20

    When I create a root class, whose methods I defined using the arrow functions. When inheriting and overwriting the original function I noticed the same issue.

    class C {
      x = () => 1; 
     };
     
    class CC extends C {
      x = (foo) =>  super.x() + foo;
    };
    
    let add = new CC;
    console.log(add.x(4));
    

    this is solved by defining the method of the parent class without arrow functions

    class C {
      x() { 
        return 1; 
      }; 
     };
     
    class CC extends C {
      x = foo =>  super.x() + foo;
    };
    
    let add = new CC;
    console.log(add.x(4));
    

提交回复
热议问题