45

I use jQuery Autosize plugin:

http://www.jacklmoore.com/autosize/

The script itself you can see here:

http://www.jacklmoore.com/js/jquery.autosize.js

This is how I use the script:

jQuery(function($){$(document).ready(function(){
$('textarea').autosize();
}

Problem N 1

Just updated the script to the latest version and it stopped to work:

"TypeError: (intermediate value)(...) is not a function"

Javascript console reports this error on the last line of the script:

}(window.jQuery || window.$)); 

Problem N 2

Script doesn't work in modal windows (PrettyPhoto) and javascript console doesn't show any errors.

Any ideas?

user
  • 751
  • 2
  • 10
  • 18
  • There's no reason to use `jQuery(function($){$(document).ready(...)})`. Passing a function into `jQuery` is the same as using `ready`. Just do `jQuery(function($) { ... });` without the call to `ready`. – T.J. Crowder Nov 13 '14 at 07:49
  • 1
    A good practice when working with multiple JS files is to add a single semicolon at the very beginning of each file to terminate any preceding malformed logic. – ShayneStatzell May 28 '15 at 18:00
  • 1
    For me it is happening when I define a function before IIFE (Immediately Invoked Function Expression). – kshirish Jun 04 '15 at 06:36

3 Answers3

149

the "TypeError: (intermediate value)(...) is not a function" pops up as the result of missing a semi colon on the function BEFORE the one it throws an error on. It might be as simple as:

jQuery(function($){$(document).ready(function(){
$('textarea').autosize();
}  
); //<-----

or it could be the function declared before that. An example of how this is cause is in this code:

var populate = function(sw) {
  myglobalswitch = sw;
  window.setTimeout(repopulate, 250, sw);
}

(function( $ ) {
$.widget( "custom.combobox", {
_create: function() {
....
})( jQuery );

results in the Intermediate value is not... on the last line: })( jQuery );

However, the fix is adding a semi colon to the populate function:

var populate = function(sw) {
  myglobalswitch = sw;
  window.setTimeout(repopulate, 250, sw);
}  ;

to prevent the parser from thinking that "var populate = ... " and (function($) ... are a single statement, the second extending from the first.

ppostma1
  • 3,616
  • 1
  • 27
  • 28
  • 1
    hint: any weird, inexplicable parsing errors are usually the result of misplaced quotes and semicolons – ppostma1 Aug 20 '14 at 18:59
  • 2
    This also occurs if an IIFE is declared after an object, that does not end with a semicolon. This happens when 'option strict' is on. – Matthew Pitts Jan 19 '16 at 18:20
  • While my code was in no way relevant to this, the semicolon FIXED EVERYTHING. Thank you! (Silly functions that return objects, in parenthesis to immediately call a function on said object). The next line's parenthesis were making the previous line parse as a function call – mix3d Aug 03 '16 at 16:15
7

FWIW the autosize invocation method has changed. If you end up here and are using it with jQuery

Previously it was

$('textarea').autosize();

The new invocation is

autosize($('textarea'));
engineerDave
  • 3,887
  • 26
  • 28
-1

You may have declared a function, inside a function, after you needed it. This was my problem.