Uncaught TypeError: undefined is not a function on loading jquery-min.js

前端 未结 13 793
北荒
北荒 2020-11-28 22:55

I\'m building a normal webpage which requires me to load about five CSS files and ten Javascript files.

  • When loading them separately in the HTML page, my webpa
13条回答
  •  日久生厌
    2020-11-28 23:49

    I just had the same message with the following code (in IcedCoffeeScript):

    f = (err,cb) ->
      cb null, true
    
    await f defer err, res
    console.log err if err  
    

    This seemed to me like regular ICS code. I unfolded the await-defer construct to regular CoffeeScript:

    f (err,res) ->
      console.log err if err
    

    What really happend was that I tried to pass 1 callback function( with 2 parameters ) to function f expecting two parameters, effectively not setting cb inside f, which the compiler correctly reported as undefined is not a function.

    The mistake happened because I blindly pasted callback-style boilerplate code. f doesn't need an err parameter passed into it, thus should simply be:

    f = (cb) ->
      cb null, true
    f (err,res) ->
      console.log err if err
    

    In the general case, I'd recommend to double-check function signatures and invocations for matching arities. The call-stack in the error message should be able to provide helpful hints.

    In your special case, I recommend looking for function definitions appearing twice in the merged file, with different signatures, or assignments to global variables holding functions.

提交回复
热议问题