Skip to content

Instantly share code, notes, and snippets.

@amcdnl
Created March 31, 2014 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amcdnl/9900479 to your computer and use it in GitHub Desktop.
Save amcdnl/9900479 to your computer and use it in GitHub Desktop.
/**
* Simplifies duplicating `define` definitions for `angular.module`.
*
* For example:
*
* define(['app/module1', 'app/module2'], function(module1, module2){
* var module3 = angular.module('app.module3', ['app.module1', 'app.module2']);
* // your code
* return module3;
* });
*
* instead `moduleDefine` translates the module name's for you like:
*
* define(['app/module1', 'app/module2'], function(module1, module2){
* var module3 = angular.moduleDefine('app.module3', arguments);
* return module3;
* });
*
* NOTE: This only works if in your module definitions if you return the module
* at the end of the definition.
*
*/
angular.moduleDefine = function(name, args){
var modules = Array.slice(args)
.filter(function (m) { return m && m.name; })
.map(function (mm) { return mm.name });
return angular.module(name, modules);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment