Require Override Modules

I am wondering how the module definition works. It is best to give an example.

If two modules with the same name are defined one after another, the second definition will not work:

define("somemodule", [], function () {return "foo";})
define("somemodule", [], function () {return "bar";})
require(["somemodule"], function (module) {console.log(module)})

He will return:

> "foo"

But if we select the module after the first definition, the second module will override the first:

define("somemodule", [], function () {return "foo";})
require(["somemodule"], function (module) {console.log(module)})
define("somemodule", [], function () {return "bar";})
require(["somemodule"], function (module) {console.log(module)})

Return:

> "foo"
> "bar"

Why does it work? I'm actually looking for an opportunity to prevent overriding modules in general. In other words, I need the code above to return "foo" all the time.

+4
source share
1 answer

I used requirejs 2.0.6. The problem is not reproduced in requirements 2.1.15. Solved!

+3
source

All Articles