0

Is there a way to get rid of the warning

JSC_NOT_FUNCTION_TYPE expressions are not callable

while packaging javascript with google closure compiler ?

var require = function(){};

var a=typeof require=="function"&& require;

function hello(name) {
   var x = 2;
   alert(a(x));
   alert('Hello, ' + name);  
}
hello('User X');

Online helper tool to run closure compiler: http://closure-compiler.appspot.com/home

sbr
  • 4,735
  • 5
  • 43
  • 49

1 Answers1

1

The problem is that a may not be a function if require isn't a function:

var a=typeof require=="function"&& require;

Instead, you may use

var a=typeof require=="function" ? require : function(){};
Oriol
  • 274,082
  • 63
  • 437
  • 513
  • Thanks @Oriol. The thing is I can't (don't want to) change that code. This part ( var a=typeof require=="function"&& require;) is the code generated by running browserify. – sbr May 01 '14 at 17:03
  • @sbr If you can't change the code I don't think you can do anything. Just ignore the warning. – Oriol May 01 '14 at 17:07
  • Maybe there is a way to specify closure options to ignore this. – sbr May 01 '14 at 17:08
  • @sbr Yes, I have just found it: `@warning_level quiet`. See the [reference](https://developers.google.com/closure/compiler/docs/api-ref#warn) – Oriol May 01 '14 at 17:09
  • but that applies to all warnings ! The thing is that this is a special case where the google closure compiler thinks it is a boolean but it is a common style used in javascript . so I don't want to suppress other warnings for this special case. – sbr May 01 '14 at 17:12
  • 1
    @sbr Of course. If you want to get all warning but this one, just ignore it. Anyway, I don't think it's a "common style": what's the point in checking if it's a function, and if not, using `false` instead? It will also throw an error when attempting to call it. – Oriol May 01 '14 at 17:50