Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RequireJS: Difference between "requirejs" and "require" functions

I am using requireJS 2.x. I found out that some tutorials (and the official docs) sometimes use

requirejs.config({ [...] }); requirejs(["module"]) ... 

and sometimes

require.config({ [...] }); require(["module"]) ... 

Is there any difference between those two functions (require and requirejs)? I could not find any word about that in the docs. :(

like image 688
Matthias Bayer Avatar asked Nov 28 '12 12:11

Matthias Bayer


People also ask

What is the difference between RequireJS CommonJS and loaders?

The short answer would be: CommonJS and AMD are specifications (or formats) on how modules and their dependencies should be declared in javascript applications. RequireJS is a script loader library that is AMD compliant, curljs being another example.

What is true regarding the differences between the define and require functions?

require() and define() both used to load dependencies. There is a major difference between these two method. Require(): Method is used to run immediate functionalities. define(): Method is used to define modules for use in multiple locations(reuse).

How do I call a function in RequireJS?

2 Answers. Show activity on this post. require(["jquery"], function ($) { function doStuff(a, b) { //does some stuff } $('#the-button'). click(function() { doStuff(4, 2); }); });

What is require () in JavaScript?

1) require() In NodeJS, require() is a built-in function to include external modules that exist in separate files. require() statement basically reads a JavaScript file, executes it, and then proceeds to return the export object.


1 Answers

They are exactly the same.

The reason is some environments might already have a require, in which case RequireJS doesn't overwrite it and allows usage of the library through requirejs

See this commit - https://github.com/jrburke/requirejs/commit/be45948433b053921dc6a6a57bf06d04e13b3b39

like image 57
Simon Smith Avatar answered Sep 20 '22 08:09

Simon Smith