# Namespace goog

code »

Base namespace for the Closure library. Checks to see goog is already defined in the current scope before assigning to prevent clobbering if base.js is loaded more than once.

## Classes

goog.Disposable Class that provides the basic implementation for disposable objects. goog.Uri This class contains setters and getters for the parts of the URI.

Show:Public Protected Private

## Global Functions

code »goog.abstractMethod ( )

When defining a class Foo with an abstract method bar(), you can do: Foo.prototype.bar = goog.abstractMethod Now if a subclass of Foo fails to override bar(), an error will be thrown when bar() is invoked. Note: This does not take the name of the function to override as an argument because that would make it more difficult to obfuscate our JavaScript code.

Throws
`Error` when invoked to indicate the method should be overridden.

code »goog.addDependency ( relPath, provides, requires, opt_isModule )

Adds a dependency from a file to the files it requires.

Parameters
relPath: `string` The path to the js file. provides: `Array` An array of strings with the names of the objects this file provides. requires: `Array` An array of strings with the names of the objects this file requires. opt_isModule: `boolean=` Whether this dependency must be loaded as a module as declared by goog.module.

code »goog.addSingletonGetter ( ctor )

Adds a `getInstance` static method that always returns the same instance object.

Parameters
ctor: `!Function` The constructor for the class to add the static method to.

code »goog.base ( me, opt_methodName, var_args ) ⇒ `*`

Call up to the superclass. If this is called from a constructor, then this calls the superclass constructor with arguments 1-N. If this is called from a prototype method, then you must pass the name of the method as the second argument to this function. If you do not, you will get a runtime error. This calls the superclass' method with arguments 2-N. This function only works if you use goog.inherits to express inheritance relationships between your classes. This function is a compiler primitive. At compile-time, the compiler will do macro expansion to remove a lot of the extra overhead that this function introduces. The compiler will also enforce a lot of the assumptions that this function makes, and treat it as a compiler error if you break them.

Parameters
me: `!Object` Should always be "this". opt_methodName: `*=` The method name if calling a super method. var_args: `...*` The rest of the arguments.
Returns
The return value of the superclass method.

code »`<T>` goog.bind ( fn, selfObj, var_args ) ⇒ `!Function`

Partially applies this function to a particular 'this object' and zero or more arguments. The result is a new function with some arguments of the first function pre-filled and the value of this 'pre-specified'. Remaining arguments specified at call-time are appended to the pre-specified ones. Also see: `#partial`. Usage:

    var barMethBound = bind(myFunction, myObj, 'arg1', 'arg2');
     barMethBound('arg3', 'arg4');

Parameters
fn: `?function(this: T, ...)` A function to partially apply. selfObj: `T` Specifies the object which this should point to when the function is run. var_args: `...*` Additional arguments that are partially applied to the function.
Returns
A partially-applied form of the function bind() was invoked as a method of.

code »goog.bindJs_ ( fn, selfObj, var_args ) ⇒ `!Function`

A pure-JS implementation of goog.bind.

Parameters
fn: `Function` A function to partially apply. selfObj: `(Object|undefined)` Specifies the object which this should point to when the function is run. var_args: `...*` Additional arguments that are partially applied to the function.
Returns
A partially-applied form of the function bind() was invoked as a method of.

code »goog.bindNative_ ( fn, selfObj, var_args ) ⇒ `!Function`

A native implementation of goog.bind.

Parameters
fn: `Function` A function to partially apply. selfObj: `(Object|undefined)` Specifies the object which this should point to when the function is run. var_args: `...*` Additional arguments that are partially applied to the function.
Returns
A partially-applied form of the function bind() was invoked as a method of.

code »goog.cloneObject ( obj ) ⇒ `*`
Deprecated: goog.cloneObject is unsafe. Prefer the goog.object methods.

Clones a value. The input may be an Object, Array, or basic type. Objects and arrays will be cloned recursively. WARNINGS: `goog.cloneObject` does not detect reference loops. Objects that refer to themselves will cause infinite recursion. `goog.cloneObject` is unaware of unique identifiers, and copies UIDs created by `getUid` into cloned results.

Parameters
obj: `*` The value to clone.
Returns
A clone of the input value.

code »goog.define ( name, defaultValue )

Defines a named value. In uncompiled mode, the value is retreived from CLOSURE_DEFINES or CLOSURE_UNCOMPILED_DEFINES if the object is defined and has the property specified, and otherwise used the defined defaultValue. When compiled, the default can be overridden using compiler command-line options.

Parameters
name: `string` The distinguished name to provide. defaultValue

code »goog.defineClass ( superClass, def ) ⇒ `!Function`

Creates a restricted form of a Closure "class": - from the compiler's perspective, the instance returned from the constructor is sealed (no new properties may be added). This enables better checks. - the compiler will rewrite this definition to a form that is optimal for type checking and optimization (initially this will be a more traditional form).

Parameters
superClass: `Function` The superclass, Object or null. def: `goog.defineClass.ClassDescriptor` An object literal describing the the class. It may have the following properties: "constructor": the constructor function "statics": an object literal containing methods to add to the constructor as "static" methods or a function that will receive the constructor function as its only parameter to which static properties can be added. all other properties are added to the prototype.
Returns
The class constructor.

code »goog.dispose ( obj )

Calls `dispose` on the argument if it supports it. If obj is not an object with a dispose() method, this is a no-op.

Parameters
obj: `*` The object to dispose of.

code »goog.disposeAll ( var_args )

Calls `dispose` on each member of the list that supports it. (If the member is an ArrayLike, then `goog.disposeAll()` will be called recursively on each of its members.) If the member is not an object with a `dispose()` method, then it is ignored.

Parameters
var_args: `...*` The list.

code »goog.exportPath_ ( name, opt_object, opt_objectToExportTo )

Builds an object structure for the provided namespace path, ensuring that names that already exist are not overwritten. For example: "a.b.c" -> a = {};a.b={};a.b.c={}; Used by goog.provide and goog.exportSymbol.

Parameters
name: `string` name of the object that this file defines. opt_object: `*=` the object to expose at the end of the path. opt_objectToExportTo: `Object=` The object to add the path to; default is |goog.global|.

code »goog.exportProperty ( object, publicName, symbol )

Exports a property unobfuscated into the object's namespace. ex. goog.exportProperty(Foo, 'staticFunction', Foo.staticFunction); ex. goog.exportProperty(Foo.prototype, 'myMethod', Foo.prototype.myMethod);

Parameters
object: `Object` Object whose static property is being exported. publicName: `string` Unobfuscated name to export. symbol: `*` Object the name should point to.

code »goog.exportSymbol ( publicPath, object, opt_objectToExportTo )

Exposes an unobfuscated global namespace path for the given object. Note that fields of the exported object *will* be obfuscated, unless they are exported in turn via this function or goog.exportProperty. Also handy for making public items that are defined in anonymous closures. ex. goog.exportSymbol('public.path.Foo', Foo); ex. goog.exportSymbol('public.path.Foo.staticFunction', Foo.staticFunction); public.path.Foo.staticFunction(); ex. goog.exportSymbol('public.path.Foo.prototype.myMethod', Foo.prototype.myMethod); new public.path.Foo().myMethod();

Parameters
publicPath: `string` Unobfuscated name to export. object: `*` Object the name should point to. opt_objectToExportTo: `Object=` The object to add the path to; default is goog.global.

code »goog.findBasePath_ ( )

Tries to detect the base path of base.js script that bootstraps Closure.

code »goog.forwardDeclare ( name )

Forward declares a symbol. This is an indication to the compiler that the symbol may be used in the source yet is not required and may not be provided in compilation. The most common usage of forward declaration is code that takes a type as a function parameter but does not need to require it. By forward declaring instead of requiring, no hard dependency is made, and (if not required elsewhere) the namespace may never be required and thus, not be pulled into the JavaScript binary. If it is required elsewhere, it will be type checked as normal.

Parameters
name: `string` The namespace to forward declare in the form of "goog.package.part".

code »goog.getCssName ( className, opt_modifier ) ⇒ `string`

Handles strings that are intended to be used as CSS class names. This function works in tandem with @see goog.setCssNameMapping. Without any mapping set, the arguments are simple joined with a hyphen and passed through unaltered. When there is a mapping, there are two possible styles in which these mappings are used. In the BY_PART style, each part (i.e. in between hyphens) of the passed in css name is rewritten according to the map. In the BY_WHOLE style, the full css name is looked up in the map directly. If a rewrite is not specified by the map, the compiler will output a warning. When the mapping is passed to the compiler, it will replace calls to goog.getCssName with the strings from the mapping, e.g. var x = goog.getCssName('foo'); var y = goog.getCssName(this.baseClass, 'active'); becomes: var x= 'foo'; var y = this.baseClass + '-active'; If one argument is passed it will be processed, if two are passed only the modifier will be processed, as it is assumed the first argument was generated as a result of calling goog.getCssName.

Parameters
className: `string` The class name. opt_modifier: `string=` A modifier to be appended to the class name.
Returns
The class name or the concatenation of the class name and the modifier.

code »goog.getHashCode ( obj ) ⇒ `number`
Deprecated: Use goog.getUid instead.

Adds a hash code field to an object. The hash code is unique for the given object.

Parameters
obj: `Object` The object to get the hash code for.
Returns
The hash code for the object.

code »goog.getMsg ( str, opt_values ) ⇒ `string`

Gets a localized message. This function is a compiler primitive. If you give the compiler a localized message bundle, it will replace the string at compile-time with a localized version, and expand goog.getMsg call to a concatenated string. Messages must be initialized in the form: `var MSG_NAME = goog.getMsg('Hello {$placeholder}', {'placeholder': 'world'});`

Parameters
str: `string` Translatable string, places holders in the form {$foo}. opt_values: `Object=` Map of place holder name to value.
Returns
message with placeholders filled.

code »goog.getMsgWithFallback ( a, b ) ⇒ `string`

Gets a localized message. If the message does not have a translation, gives a fallback message. This is useful when introducing a new message that has not yet been translated into all languages. This function is a compiler primitive. Must be used in the form: `var x = goog.getMsgWithFallback(MSG_A, MSG_B);` where MSG_A and MSG_B were initialized with goog.getMsg.

Parameters
a: `string` The preferred message. b: `string` The fallback message.
Returns
The best translated message.

code »goog.getObjectByName ( name, opt_obj )

Returns an object based on its fully qualified external name. The object is not found if null or undefined. If you are using a compilation pass that renames property names beware that using this function will not find renamed properties.

Parameters
name: `string` The fully qualified name. opt_obj: `Object=` The object within which to look; default is |goog.global|.
Returns
The value (object or primitive) or, if not found, null.

code »goog.getPathFromDeps_ ( rule ) ⇒ `?string`

Looks at the dependency rules and tries to determine the script file that fulfills a particular rule.

Parameters
rule: `string` In the form goog.namespace.Class or project.script.
Returns
Url corresponding to the rule, or null.

code »goog.getUid ( obj ) ⇒ `number`

Gets a unique ID for an object. This mutates the object so that further calls with the same object as a parameter returns the same value. The unique ID is guaranteed to be unique across the current session amongst objects that are passed into `getUid`. There is no guarantee that the ID is unique or consistent across sessions. It is unsafe to generate unique ID for function prototypes.

Parameters
obj: `Object` The object to get the unique ID for.
Returns
The unique ID for the object.

code »goog.globalEval ( script )

Evals JavaScript in the global scope. In IE this uses execScript, other browsers use goog.global.eval. If goog.global.eval does not evaluate in the global scope (for example, in Safari), appends a script tag instead. Throws an exception if neither execScript or eval is defined.

Parameters
script: `string` JavaScript string.

code »goog.globalize ( obj, opt_global )
Deprecated: Properties may be explicitly exported to the global scope, but this should no longer be done in bulk.

Globalizes a whole namespace, such as goog or goog.lang.

Parameters
obj: `Object` The namespace to globalize. opt_global: `Object=` The object to add the properties to.

code »goog.hasUid ( obj ) ⇒ `boolean`

Whether the given object is alreay assigned a unique ID. This does not modify the object.

Parameters
obj: `Object` The object to check.
Returns
Whether there an assigned unique id for the object.

code »goog.identityFunction ( opt_returnValue, var_args )
Deprecated: Use goog.functions.identity instead.

The identity function. Returns its first argument.

Parameters
opt_returnValue: `*=` The single value that will be returned. var_args: `...*` Optional trailing arguments. These are ignored.
Returns
The first argument. We can't know the type -- just pass it along without type.

code »goog.importModule_ ( src )

Given a URL initiate retrieval and execution of the module.

Parameters
src: `string` Script source URL.

code »goog.importScript_ ( src, opt_sourceText )

Imports a script if, and only if, that script hasn't already been imported. (Must be called at execution time)

Parameters
src: `string` Script source. opt_sourceText: `string=` The optionally source text to evaluate

code »goog.inHtmlDocument_ ( ) ⇒ `boolean`

Tries to detect whether is in the context of an HTML document.

Returns
True if it looks like HTML document.

code »goog.inherits ( childCtor, parentCtor )

Inherit the prototype methods from one constructor into another. Usage:

     function ParentClass(a, b) { }
     ParentClass.prototype.foo = function(a) { };

     function ChildClass(a, b, c) {
       ChildClass.base(this, 'constructor', a, b);
     }
     goog.inherits(ChildClass, ParentClass);

     var child = new ChildClass('a', 'b', 'see');
     child.foo(); // This works.

Parameters
childCtor: `Function` Child class. parentCtor: `Function` Parent class.

code »goog.isArray ( val ) ⇒ `boolean`

Returns true if the specified value is an array.

Parameters
val: `?` Variable to test.
Returns
Whether variable is an array.

code »goog.isArrayLike ( val ) ⇒ `boolean`

Returns true if the object looks like an array. To qualify as array like the value needs to be either a NodeList or an object with a Number length property.

Parameters
val: `?` Variable to test.
Returns
Whether variable is an array.

code »goog.isBoolean ( val ) ⇒ `boolean`

Returns true if the specified value is a boolean.

Parameters
val: `?` Variable to test.
Returns
Whether variable is boolean.

code »goog.isDateLike ( val ) ⇒ `boolean`

Returns true if the object looks like a Date. To qualify as Date-like the value needs to be an object and have a getFullYear() function.

Parameters
val: `?` Variable to test.
Returns
Whether variable is a like a Date.

code »goog.isDef ( val ) ⇒ `boolean`

Returns true if the specified value is not undefined. WARNING: Do not use this to test if an object has a property. Use the in operator instead.

Parameters
val: `?` Variable to test.
Returns
Whether variable is defined.

code »goog.isDefAndNotNull ( val ) ⇒ `boolean`

Returns true if the specified value is defined and not null.

Parameters
val: `?` Variable to test.
Returns
Whether variable is defined and not null.

code »goog.isFunction ( val ) ⇒ `boolean`

Returns true if the specified value is a function.

Parameters
val: `?` Variable to test.
Returns
Whether variable is a function.

code »goog.isInModuleLoader_ ( ) ⇒ `boolean`

Returns
Whether a goog.module is currently being initialized.

code »goog.isNull ( val ) ⇒ `boolean`

Returns true if the specified value is null.

Parameters
val: `?` Variable to test.
Returns
Whether variable is null.

code »goog.isNumber ( val ) ⇒ `boolean`

Returns true if the specified value is a number.

Parameters
val: `?` Variable to test.
Returns
Whether variable is a number.

code »goog.isObject ( val ) ⇒ `boolean`

Returns true if the specified value is an object. This includes arrays and functions.

Parameters
val: `?` Variable to test.
Returns
Whether variable is an object.

code »goog.isProvided_ ( name ) ⇒ `boolean`

Check if the given name has been goog.provided. This will return false for names that are available only as implicit namespaces.

Parameters
name: `string` name of the object to look for.
Returns
Whether the name has been provided.

code »goog.isString ( val ) ⇒ `boolean`

Returns true if the specified value is a string.

Parameters
val: `?` Variable to test.
Returns
Whether variable is a string.

code »goog.loadModule ( moduleDef )

Parameters
moduleDef: `(function(?): ?|string)` The module definition.

code »goog.loadModuleFromSource_ ( )
code »goog.loadQueuedModules_ ( )

Load any deferred goog.module loads.

code »goog.logToConsole_ ( msg )

Parameters
msg

code »goog.mixin ( target, source )

Copies all the members of a source object to a target object. This method does not work on all browsers for all objects that contain keys such as toString or hasOwnProperty. Use goog.object.extend for this purpose.

Parameters
target: `Object` Target. source: `Object` Source.

code »goog.module ( name )

goog.module serves two purposes: - marks a file that must be loaded as a module - reserves a namespace (it can not also be goog.provided) and has three requirements: - goog.module may not be used in the same file as goog.provide. - goog.module must be the first statement in the file. - only one goog.module is allowed per file. When a goog.module annotated file is loaded, it is loaded enclosed in a strict function closure. This means that: - any variable declared in a goog.module file are private to the file, not global. Although the compiler is expected to inline the module. - The code must obey all the rules of "strict" JavaScript. - the file will be marked as "use strict" NOTE: unlike goog.provide, goog.module does not declare any symbols by itself.

Parameters
name: `string` Namespace provided by this file in the form "goog.package.part", is expected but not required.

code »goog.now ( ) ⇒ `number`

Returns
An integer value representing the number of milliseconds between midnight, January 1, 1970 and the current time.

code »goog.nullFunction ( ) ⇒ `void`

Null function used for default values of callbacks, etc.

Returns
Nothing.

code »goog.onScriptLoad_ ( script, scriptIndex ) ⇒ `boolean`

A readystatechange handler for legacy IE

Parameters
script scriptIndex

code »goog.partial ( fn, var_args ) ⇒ `!Function`

Like bind(), except that a 'this object' is not required. Useful when the target function is already bound. Usage: var g = partial(f, arg1, arg2); g(arg3, arg4);

Parameters
fn: `Function` A function to partially apply. var_args: `...*` Additional arguments that are partially applied to fn.
Returns
A partially-applied form of the function bind() was invoked as a method of.

code »goog.provide ( name )

Creates object stubs for a namespace. The presence of one or more goog.provide() calls indicate that the file defines the given objects/namespaces. Provided objects must not be null or undefined. Build tools also scan for provide/require statements to discern dependencies, build dependency files (see deps.js), etc.

Parameters
name: `string` Namespace provided by this file in the form "goog.package.part".

code »goog.removeHashCode ( obj )
Deprecated: Use goog.removeUid instead.

Removes the hash code field from an object.

Parameters
obj: `Object` The object to remove the field from.

code »goog.removeUid ( obj )

Removes the unique ID from an object. This is useful if the object was previously mutated using `goog.getUid` in which case the mutation is undone.

Parameters
obj: `Object` The object to remove the unique ID field from.

code »goog.require ( name )

Implements a system for the dynamic resolution of dependencies that works in parallel with the BUILD system. Note that all calls to goog.require will be stripped by the JSCompiler when the --closure_pass option is used.

Parameters
name: `string` Namespace to include (as was given in goog.provide()) in the form "goog.package.part".
Returns
If called within a goog.module file, the associated namespace or module otherwise null.

code »goog.retrieveAndExecModule_ ( src )

Retrieve and execute a module.

Parameters
src: `string` Script source URL.

code »goog.scope ( fn )

Allow for aliasing within scope functions. This function exists for uncompiled code - in compiled code the calls will be inlined and the aliases applied. In uncompiled code the function is simply run since the aliases as written are valid JavaScript.

Parameters
fn: `function()` Function to call. This function can contain aliases to namespaces (e.g. "var dom = goog.dom") or classes (e.g. "var Timer = goog.Timer").

code »goog.setCssNameMapping ( mapping, opt_style )

Sets the map to check when returning a value from goog.getCssName(). Example:

     goog.setCssNameMapping({
       "goog": "a",
       "disabled": "b",
     });

     var x = goog.getCssName('goog');
     // The following evaluates to: "a a-b".
     goog.getCssName('goog') + ' ' + goog.getCssName(x, 'disabled')

When declared as a map of string literals to string literals, the JSCompiler will replace all calls to goog.getCssName() using the supplied map if the --closure_pass flag is set.

Parameters
mapping: `!Object` A map of strings to strings where keys are possible arguments to goog.getCssName() and values are the corresponding values that should be returned. opt_style: `string=` The style of css name mapping. There are two valid options: 'BY_PART', and 'BY_WHOLE'.

code »goog.setTestOnly ( opt_message )

Marks that the current file should only be used for testing, and never for live code in production. In the case of unit tests, the message may optionally be an exact namespace for the test (e.g. 'goog.stringTest'). The linter will then ignore the extra provide (if not explicitly defined in the code).

Parameters
opt_message: `string=` Optional message to add to the error that's raised when used in production code.

code »goog.tagUnsealableClass ( ctr )

Sealing classes breaks the older idiom of assigning properties on the prototype rather than in the constructor. As such, goog.defineClass must not seal subclasses of these old-style classes until they are fixed. Until then, this marks a class as "broken", instructing defineClass not to seal subclasses.

Parameters
ctr: `!Function` The legacy constructor to tag as unsealable.

code »goog.typeOf ( value ) ⇒ `string`

This is a "fixed" version of the typeof operator. It differs from the typeof operator in such a way that null returns 'null' and arrays return 'array'.

Parameters
value: `*` The value to get the type of.
Returns
The name of the type.

code »goog.wrapModule_ ( srcUrl, scriptText ) ⇒ `string`

Return an appropriate module text. Suitable to insert into a script tag (that is unescaped).

Parameters
srcUrl scriptText

code »goog.writeScriptTag_ ( src, opt_sourceText ) ⇒ `boolean`

The default implementation of the import function. Writes a script tag to import the script.

Parameters
src: `string` The script url. opt_sourceText: `string=` The optionally source text to evaluate
Returns
True if the script was imported, false otherwise.

code »goog.writeScripts_ ( )

Resolves dependencies based on the dependencies added using addDependency and calls importScript_ in the correct order.

## Global Properties

code »goog.DEPENDENCIES_ENABLED : `boolean`

True if goog.dependencies_ is available.

code »goog.IS_OLD_IE_ : `?`
code »goog.UID_PROPERTY_ : `string`

Name for unique ID property. Initialized in a way to help avoid collisions with other closure JavaScript on the same page.

code »goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_ : `string`

Name for unsealable tag property.

code »goog.basePath : `string`

Path for included scripts.

code »goog.cssNameMappingStyle_ : `(string|undefined)`

Optional obfuscation style for CSS class names. Should be set to either 'BY_WHOLE' or 'BY_PART' if defined.

code »goog.cssNameMapping_ : `(Object|undefined)`

Optional map of CSS class names to obfuscated names used with goog.getCssName().

code »goog.dependencies_ : `Object`

This object is used to keep track of dependencies and other data that is used for loading scripts.

code »goog.evalWorksForGlobals_ : `?boolean`

Indicates whether or not we can call 'eval' directly to eval code in the global scope. Set to a Boolean by the first call to goog.globalEval (which empirically tests whether eval works for globals). @see goog.globalEval

code »goog.global : `global this`

Reference to the global context. In most cases this will be 'window'.

code »goog.implicitNamespaces_ : `Object.<string>`

Namespaces implicitly defined by goog.provide. For example, goog.provide('goog.events.Event') implicitly declares that 'goog' and 'goog.events' must be namespaces.

code »goog.included_ : `Object`

Object used to keep track of urls that have already been added. This record allows the prevention of circular dependencies.

code »goog.instantiatedSingletons_ : `!Array`

All singleton classes that have been instantiated, for testing. Don't read it directly, use the `goog.testing.singleton` module. The compiler removes this variable if unused.

code »goog.lastNonModuleScriptIndex_ : `number`
code »goog.loadedModules_ : `{}`

The registry of initialized modules: the module identifier to module exports map.

code »goog.moduleLoaderState_ : `({moduleName: (string|undefined), exportTestMethods: boolean}|null)`
code »goog.queuedModules_ : `Array.<string>`
code »goog.uidCounter_ : `number`

Counter for UID.

## Compiler Constants

code »goog.DEBUG : `boolean`
code »goog.ENABLE_DEBUG_LOADER : `boolean`
code »goog.LOAD_MODULE_USING_EVAL : `boolean`
code »goog.LOCALE : `string`
code »goog.NATIVE_ARRAY_PROTOTYPES : `boolean`
code »goog.STRICT_MODE_COMPATIBLE : `boolean`
code »goog.TRUSTED_SITE : `boolean`