What is define([ , function ]) in JavaScript?

JavascriptFunctionRequirejs Define

Javascript Problem Overview


I see this being used all the time in JavaScript:

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

});

What is the define function?

Javascript Solutions


Solution 1 - Javascript

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.

Solution 2 - Javascript

define() is part of the AMD spec of js

See:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionvinzzzView Question on Stackoverflow
Solution 1 - JavascriptClaudio RediView Answer on Stackoverflow
Solution 2 - JavascriptTom StudeeView Answer on Stackoverflow