Question

Is

define(['a', 'b'],
   function(require, exports, module) { } );

equivalent to this

define(function(require, exports, module) { 
      require(['a', 'b'])
});

If not, how is it different?

Was it helpful?

Solution

Your first bit of code should actually be

define(['a', 'b'], function(a, b) { } );

and the second bit as

define(function(require, exports, module) { 
    var a = require('a');
    var b = require('b');
});

When you use the second bit of code requirejs has to parse the function.toString() to find the require statements and add them as a dependency.

http://requirejs.org/docs/api.html#define

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top