amd/define

Null implementation of CommonJS Asynchronous Module Definition (AMD).

This null implementation triggers the callback functions registered with define() immediately or throws an error.  It does not load missing modules, and does not wait for the definition of all dependencies to trigger the factory callback at a later time.

This null implementation is intended to replace requireJS when optimized scripts are combined into a single file by the optimization tool.  It expects that all dependencies will be defined before they are required.

When a define() function is already available, which supports CommonJS AMD, this module registers itself.  This allows to load this module dynamically for unit tests using requireJS.  The existing define() method is preserved.

Reference

http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition

Author: Eric Bréchemier git.nosp@m.hub@eric.brech.nosp@m.emier.name

Copyright

Eric Bréchemier © 2011, Some Rights Reserved Legal-Box SAS © 2010-2011, All Rights Reserved

License

BSD License http://creativecommons.org/licenses/BSD/

Version

2011-08-14

Summary
amd/defineNull implementation of CommonJS Asynchronous Module Definition (AMD).
Functions
define([id,] [dependencies,] factory)Define a module.

Functions

define([id,] [dependencies,] factory)

Define a module.

Parameters

idstring, optional identifier of the module.  This must be an absolute id (not starting with ‘.’ or ‘..’).
dependenciesarray of strings, optional, defaults to [“require”, “exports”, “module”].  The dependencies ids may be relative to the module id if it is specified.
factoryfunction, callback which will be called at most once, when all dependencies are available.  If truthy, the return value of the function will be cached and associated with given id, unless the id is omitted.  For each dependency, the cached value associated with the dependency id is provided as argument to the factory callback, in the same order.

Note

The dependencies “require”, “exports” and “module” have a special meaning, and special values are provided for corresponding arguments: require - function, require(id) returns the cached value associated with the id, or throws an error if the module is not loaded.  In this null implementation, any module defined without an id will be considered as missing. exports - object, an alternate way to define the return value of the factory function.  In this implementation, the exports is cached instead of the return value of the factory when the return value is falsy.  It is ignored otherwise. module - object, with a property ‘id’ set to the value provided in the call to define.  In this null implementation, in case the id is omitted, the module.id is undefined.  The module object has no ‘uri’ property.

Close