1

I'm having a problem in my GWT app, in which I use another script that itself uses the underscore.js library. This script defines the global variable var _;.

The issue is that the GWT generated code also defines var _ for app-specific purposes; this clashes with the _ that's defined in the other script.

I also don't know what other global variables GWT may be defining that other scripts may unwittingly interfere with.

(Edit: it seems from this question that _ is the only symbol it uses).

Is there any way to put GWT's generated variables into a separate global variable of my choosing?

Community
  • 1
  • 1
funkybro
  • 8,432
  • 6
  • 39
  • 52

1 Answers1

2

Unless you use the xs linker (which is now deprecated in favor of the xsiframe linker) or the sso linker, GWT code runs within an iframe so that it doesn't pollute the global namespace and more importantly is (almost) immune to external scripts polluting the global namespace.

The only script running in the HTML host page JS environment is the *.nocache.js script, which defines a single function (by the name of your GWT module) and simply calls it, so as to specifically not pollute the global namespace.

The question you linked to talks about code that runs within the iframe sandbox, so it shouldn't conflict with underscore.js.

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • Indeed. I am in fact applying my own custom linker to my app so as to run GWT code outwith the usual browser context; looks like I need to emulate the `iframe` namespace segregation too. – funkybro Mar 22 '12 at 16:11