1. Get rid of the anonymous functions -- they just mess things up in
my experience. If you want the output wrapped, use
--output_wrapper='(function(){%output%})()' (or your favourite one
including window and/or document and/or undefined...). That will
actually wrap the output of the compiler. Right now, that is not
something that's happening, since closure compiler will add code of
its own to the output in advanced mode. And things like window.Main =
Main become unnecessary.
2. You're missing annotations. Things like /** @constructor */.
3. paddle.someUseMethod will try to get it on Paddle.prototype, not on
the Paddle. I'm surprised this works in simple mode.
4. On your page, main.init() will not work, since init is likely to
have been renamed. You need to export that property, e.g.
goog.exportProperty(Main.prototype, 'init', Main.prototype.init);
On Tue, Apr 16, 2013 at 1:29 PM, Adam Holland <
adgho...@gmail.com> wrote:
> Hi, I'm trying to learn how to use the compiler.
>
> I can get it to work with simple optimisations but not with the advanced
> mode. If someone could tell me what I am doing wrong I would be very
> grateful.
>
> I am using a simple test to try and get things working, here is my code:
>
> // main.js
> ------------------------------------------------------------------------------------
>
>
> goog.require('Test.Paddle');
>
>
> goog.provide('Test.Main');
>
>
> (function ( window ) {
>
> "use strict";
>
>
> function Main () {
>
> }
>
>
> Main.prototype.init = function(){
>
> alert( "MAIN" );
>
> var paddle = new Paddle();
>
> paddle.someUsedMethod();
>
> };
>
>
> window.Main = Main;
>
> })( window );
>
>
> goog.exportSymbol('Test.Main', Main);
>
>
> //
> -------------------------------------------------------------------------------------------------
>
>
>
>
>
> // paddle.js
> ------------------------------------------------------------------------------------
>
>
> goog.provide('Test.Paddle');
>
>
> (function ( window ) {
>
> "use strict";
>
>
> function Paddle() {
>
> }
>
>
> Paddle.someUsedMethod = function () {
>
> alert( "HEY THIS IS A PADDLE" );
>
> };
>
>
> window.Paddle = Paddle;
>
> })( window );
>
>
>
> //
> -------------------------------------------------------------------------------------------------
>
>
> Then in my html I have a script tag that creates a "main":
>
> <script>
> var main = new Test.Main();
> main.init();
> </script>
>
>
>
> So this works with simple_optimizations or with the "base.js" loader and
> "deps.js" file but not with ADVANCED_OPTIMIZATIONS, I am not exporting any
> symbols apart from the Main, this is because I am trying to access it
> externally. Is that correct?
>
> Thanks for any help, Adam
>
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Closure Compiler Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
closure-compiler-d...@googlegroups.com.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>