back to Overview


Defines a module that can be returned by require, in case you don't have a AMD loader.
Available in all modules.


define(name, factoryFunction)


the name of the module to request. In Minified's implementation, only 'minified' is supported.
is a function(require) will be called the first time the name is defined to obtain the module reference. It received a reference to require() (which is required for AMD backward-compatibility) and must return the value that is returned by require(). The function will only be called once, its result will be cached.
A reference to require(). While you could use require() from the global context, this would prevent backward compatibility with AMD.
(callback return value)
The reference to be returned by require().


Defines a module that can be returned by require(), in case you don't have a AMD loader. If you have a AMD loader before you include Minified, define() will not be set and you can use the AMD loader's (more powerful) variant.

Minified's versions of require() and define() are very simple and can not resolve things like circular references. Also, they are not AMD-compatible and only useful for simple modules. If you need to work with real AMD libraries that are not written for Minified, you need a real AMD loader.


Creates a simple module and uses it:

define('makeGreen', function(require) {
    var MINI = require('minified'), $ = MINI.$; // obtain own ref to Minified
    return function(list) {
        $(list).set({$color: '#0f0', $backgroundColor: '#050'});

var makeGreen = require('makeGreen');

See also..


comments powered by Disqus

back to Overview