-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
i've noticed a subtle difference between requirejs and dojo's loader and i've come to the conclusion that it's a bug in requirejs.
for a module like this,
define([], function (a, b, c) { });
using dojo - a
, b
, c
will be undefined
. the module explicitly states that it has no dependencies so none are given
using requirejs - a
, b
, c
, will be require
, exports
, module
.
in dojo, if you want require
, exports
and module
you would do this
define(function (require, exports, module) { });
which is the same for requirejs too.
this came up when https://github.com/kriszyp/put-selector/blob/v0.3.2/put.js#L3 failed to work when loaded via requirejs because it was assuming the behavior that is in dojo's loader.
the spec says:
The dependencies argument is optional. If omitted, it should default to ["require", "exports", "module"].
in the first case above, the dependencies argument is not omitted, it's explicitly empty, so this is why i came to the conclusion that it's a bug in requirejs.
it looks like https://github.com/jrburke/requirejs/blob/master/require.js#L1952-L1978 is what needs some adjusting. something along the lines of:
if (!isArray(deps)) {
callback = deps;
deps = [];
// only do factory scanning if necessary
if (isFunction(callback) && callback.length) {
callback.toString()
// continue with the rest of that block as it is
}
}