April 18, 2007
GWT Resource Injection and script ready-function

Google Web Toolkit modules can cause the automatic loading of JavaScript resources. Part of making this work is providing a JavaScript function that is evaluated to determine when the script has loaded successfully. Google provides an example but there's one bit that's not covered. If you've used objects to create a sort of namespace for your functions, for instance

foo = {
   ...,
   bar: function(a) {
      ...
   }
}

then when you write the ready-function you can't just use

if ($wnd.foo.bar) { 
    return true;
} else {
    return false;
}

You have to test for the existence of $wnd.foo before testing for $wnd.foo.bar because otherwise the function fails and isn't executed again.

if ($wnd.foo && $wnd.foo.bar) {
    return true;
} else {
    return false;
}
Posted by Alex at April 18, 2007 11:30 PM
Comments
Post a comment
Name:


Email Address:


URL:


Comments:


Remember info?