You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
The current pattern for defining (or getting) a module is rather error-prone:
angular.module('foo', ['dependencies']); //creates a module object and returns it
angular.module('foo', []); //creates a module object and returns it
angular.module('foo'); //returns a module if it exists
There are at least two issues:
The same verb (module) is used for reading and writing. This is kinda similar to JQuery attr() function which can read or write depending on how it is called, but it's error prone and not very intuitive.
That empty array is just ugly. Why create an extra object just to indicate that this is a special call? It is easy to miss (because empty array has a tendency in our mind to be omitted since it is "nothing" but in this context it makes a big difference).
How about using a pattern that already exists? require() and define():
angular.define('foo', ['dependencies'] ) //defines a module. The dependencies array is optional
angular.require('moduleName') //returns the module