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

前端 未结 7 1909
不思量自难忘°
不思量自难忘° 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:25

    I have faced this issue when I created a new ES2015 class where the property name was equal to the method name.

    e.g.:

    class Test{
      constructor () {
        this.test = 'test'
      }
    
      test (test) {
        this.test = test
      }
    }
    
    let t = new Test()
    t.test('new Test')
    

    Please note this implementation was in NodeJS 6.10.

    As a workaround (if you do not want to use the boring 'setTest' method name), you could use a prefix for your 'private' properties (like _test).

    Open your Developer Tools in jsfiddle.

提交回复
热议问题