Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

How about using require() and define() for modules? #9267

Closed
@alexewerlof

Description

@alexewerlof

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:

  1. 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.
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions