Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between define and require in RequireJS? [duplicate]

What is the difference between define and require, and when should I use each of them? I have read different answers on Stack Overflow, but I still haven't been able to understand.

For example, if this was on main.js (config file require points to), what is the difference?

define(["jquery"], function($) {
 do something with $            
});

require(["jquery"], function($) {
 do something with $            
});

Is $/jQ guaranteed to be loaded and ready in both?

like image 279
Adi Avatar asked Mar 08 '13 10:03

Adi


1 Answers

They do the same thing internally. But...... you should define your entry point of your app using require and define the rest of the modules using define. I find that this keeps it clear what role the current module you're looking at is actually playing in terms of your whole app.

like image 126
Amy Avatar answered Nov 11 '22 11:11

Amy