I recently received a code review from a colleague where he wanted my opinion on a different approach for defining JS modules and pulling in dependencies with requireJS. The typical approach is:
define('module-name',
['dep1', 'dep2', 'dep3'],
function(dep1, dep2, dep3){
//Do stuff...
});
The approach he submitted for review is:
define('module-name',
function(){
var dep1 = require('dep1');
var dep2 = require('dep2');
var dep3 = require('dep3');
//Do stuff...
});
His reasoning behind declaring each require verbosely was that it can be a pain when adding or removing dependencies to the array. You have to be sure the order of your parameters in the callback function is correct. His method guarantees that you can't accidentally remove a dependency and leave the parameter.
I know that the first approach is what's detailed in the requireJS documentation, but is there any sort of difference? My only argument against his approach is that it's not what's typically done, but I'd like to know if there are any technical reasons against it.