jjrabbit
jjrabbit

Reputation: 363

Receiving "variable myFunction is undeclared" in Google Closure Compiler

Attempting to compile two JavaScript files where a function used by both files is declared in only one of those files gives an undeclared error.

I tried declaring it in my externs file by entering var myFunction = function() {};

However if I compile doing that I receive: Variable myFunction declared more than once. First occurrence: [path]

How do I let Google Closure Compiler know that a function has already been declared if not in the externs file?

Upvotes: 2

Views: 348

Answers (1)

Chad Killingsworth
Chad Killingsworth

Reputation: 14411

As you appear to be compiling the files separately, your extern method was correct. But the extern is only needed to compile the file that does not define the function.

Since the other file does define the function, it does not need the extern.

Upvotes: 1

Related Questions