Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

What is define () in JavaScript?

Advertisements. The define() function can be used to load the modules (module can be an object, function, class or a code which is executed after loading a module). You can load different versions of the same module in the same page.

Can you define a function twice in JavaScript?

functions are data in memory stack, so when you define another function with the same name, it overrides the previous one. Show activity on this post. Well obviously you're not meant to define the same function twice. However, when you do, the latter definition is the only 1 that applies.

What are the different ways of defining function in JavaScript?

There are 3 ways of writing a function in JavaScript: Function Declaration. Function Expression. Arrow Function.


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.


define() is part of the AMD spec of js

See:

  • https://github.com/amdjs/amdjs-api/wiki/AMD

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