I am working on a custom RequireJS plugin that needs to create a new object instance every time it is called.
For illustration purposes, consider the following:
define("loader", {
load: function(name, req, onload, config) {
var instance = GlobalGetter.get(name);
instance.id = new Date().getTime() * Math.random();
onload(instance);
}
});
require(["loader!goo"], function(instance) {
console.log(instance.id); // 12345
});
require(["loader!goo"], function(instance) {
console.log(instance.id); // 12345 SAME!
});
In this example, the "goo
" module is only loaded once, causing both require callbacks to receive the same object instance. While this behavior makes sense in the context of RequireJS, it does not align with my requirements.
Is there a way to configure a plugin so that it always returns a fresh result? Although RequireJS generally meets my needs, I'm looking for a solution to address this specific scenario. Are there any official or unofficial methods to achieve the desired outcome?
Thank you.