suppose you goog.require goog.ui.Component. who decides whether you
get the amend or not?
We are trying to move towards a world where everything provides some
symbol. That way, you can simply pass all the files in a directory to
a tool, and tell the tool what the entry points are, and it will
remove files that you aren't using.
I think this proposal would work well for a dependency tree of D = 2
(where you develop application X, and X depends on Closure). But I
think it would get unmanageable for any D > 2 (where X depends on some
other library Y, and X and Y both depend on Closure).
I can think of lots of one-offs to shim that problem (the compiler's
--define flag is one example of this, goog.amend is another), but I'm
worried about the proliferation of lots of shims that make the library
confusing and difficult to reason about. If we ever have
goog.amend.amend, we've gone too far :)
Folks have suggested elsewhere that Closure should move towards modules
http://wiki.ecmascript.org/doku.php?id=harmony:modules
or some requirejs-like solution, where the module is not necessarily
initialized when it is declared. That would make it a lot easier to
add hooks like this, so you could tell the module loader "make sure
the base.js module hasn't loaded yet, and call this handler if it does
load".
Alternatively, i've heard proposals that there should be a compiler
mode where we outright forbid certain types of initialization in the
global scope, and instead force you to register a static
initialization block. I vaguely recall that this is basically how GWT
works (because they have to implement Java's late-initializer logic in
JS).
You only need to do this in non-compiled mode, right?