goog provide and require

Each javascript file provides a unique namespace and can require any number of other namespaces:



That is all. From there on you code as you may.

All the goog.require and goog.provide declarations will be removed when your application gets built.

It is advised to put all declarations at the top of your file.

The Functions

Heavily quoting the Google Closure's Library Tutorial

Function goog.provide()

Type: string Default: None

The goog.provide() function ensures the existence of the JavaScript object structure indicated by its argument. It checks to see whether each object property in the path expression exists, and if it doesn't exist it initializes it.

The function call goog.provide('app.view.about') is equivalent to:

app = app || {};
app.view = app.view || {};
app.view.about = app.view.about || {};

Because goog.provide() only initializes properties if they don't already exist, it never overwrites properties.

With goog.provide() you declare namespaces, not directory structure. Just provide a unique namespace and then require it. It's as simple as that.

Function goog.require()

Type: string Default: None

Implements a system for the dynamic resolution of dependencies that works in parallel with the BUILD system.

For a better understanding of the inner workings check out Google Closure's Library Tutorial and scroll to "Creating a Namespace with goog.provide()".