require() issue - TypeError - newbie question

34 views
Skip to first unread message

dali

unread,
May 22, 2013, 11:17:13 AM5/22/13
to closure-lib...@googlegroups.com
I have a
   require('goog.editor.SeamlessField');
statement at the top of my js file.

When I write
   var test = goog.editor.SeamlessField;
further below in the file, I get a 
   TypeError: goog.editor is undefined
(this is not compiled).

However, when I write the var test... statement inside a document.ready function, it works.

Where is the issue here? Is the require() statement not supposed to ensure I can use the Field anywhere in my js doc and not have to wait for document ready?

Thanks!!

John Munro

unread,
May 22, 2013, 3:39:24 PM5/22/13
to closure-lib...@googlegroups.com
Make sure you have

<script type="text/javascript" src="../closure-library/closure/goog/base.js"></script>
<script type="text/javascript" src="deps.js"></script>
<script type="text/javascript">goog.require('mynamespace.start');</script>

Where deps.js is generated by depswriter and mynamespace.start is the namespace of your page.  Then at the bottom of body put

<script type="text/javascript">mynamespace.start();</script>

Nick Santos

unread,
May 22, 2013, 3:56:47 PM5/22/13
to closure-lib...@googlegroups.com
The 'hello world' docs talk about this in pretty good detail:
https://developers.google.com/closure/library/docs/gettingstarted
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Closure Library Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to closure-library-d...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

dali

unread,
May 22, 2013, 6:11:45 PM5/22/13
to closure-lib...@googlegroups.com
Thanks to both of you!
I believe I've fallen into the trap:
Note: Do not put your goog.require() statements in the same script tag as the entry point to code that uses the goog.required functions or classes

On deps.js:
says it's deprecated.
I've tried closurebuilder but am encountering a (documentation?) issue. I'll open a new topic for this to keep it clean.

Reply all
Reply to author
Forward
0 new messages