Search code examples
google-closure-compiler

JSC_UNDEFINED_VARIABLE variable global_var is undeclared


I have a global variable storing a array passed from server.

HTML file

global_var = {{hello_obj}}

hello.js

var hello = global_var; Closure compiler gives error:

[JSC_UNDEFINED_VARIABLE] variable global_var is undeclared

How to solve this error?


Solution

  • window.global_var will tell Closure this is a global.

    If you use (or intend to use) advanced optimizations, you may wish to go with window['global_var'] to ensure the property isn't renamed.