When should I use require() and when to use define()?

后端 未结 5 1829
抹茶落季
抹茶落季 2020-11-30 16:19

I have being playing around with requirejs for the last few days. I am trying to understand the differences between define and require.

Define seems to allow for mo

5条回答
  •  隐瞒了意图╮
    2020-11-30 16:46

    With define you register a module in require.js that you can then depend on in other module definitions or require statements. With require you "just" load/use a module or javascript file that can be loaded by require.js. For examples have a look at the documentation

    My rule of thumb:

    • Define: If you want to declare a module other parts of your application will depend on.

    • Require: If you just want to load and use stuff.

提交回复
热议问题