7

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?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Adi
  • 4,034
  • 13
  • 56
  • 78

1 Answers1

3

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.

Amy
  • 7,388
  • 2
  • 20
  • 31