180

I see this being used all the time in JavaScript:

define(['param1', 'param2'], function() {

});

What is the define function?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
vinzzz
  • 2,084
  • 2
  • 14
  • 23
  • 4
    Look up [RequireJS](http://requirejs.org) and the [AMD API](https://github.com/amdjs/amdjs-api/wiki/AMD). – user2246674 Jun 05 '13 at 21:55
  • 3
    I would refer anyone who wants to learn more about this, AMD or different modules in JS I'd refer you to an excellent article written not by me on Medium https://medium.freecodecamp.org/javascript-modules-a-beginner-s-guide-783f7d7a5fcc – TheBen Feb 27 '19 at 22:50

2 Answers2

128

That's probably a requireJS module definition

Check here for more details

RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node. Using a modular script loader like RequireJS will improve the speed and quality of your code.

Claudio Redi
  • 67,454
  • 15
  • 130
  • 155
  • See https://stackoverflow.com/a/10331369/1549918 for a good explanation of `define`, it's purpose and the function definition – Chris Halcrow Dec 20 '22 at 00:38
91

define() is part of the AMD spec of js

See:

Edit: Also see @Claudio Redi's answer. Likely the more relevant explanation.

Chris Halcrow
  • 28,994
  • 18
  • 176
  • 206
Tom Studee
  • 10,316
  • 4
  • 38
  • 42