I think that any delay or delay should occur inside the definition function, or you can use some callback pattern, for example:
require(['b'], function(b){
b.getData(
function(data) {
console.log(data);
}
);
});
define(function(){
this.getData = function(callback) {
setTimeout(function(_callback){
return function() {
_callback({'foo':'bar'});
}
}(callback), 1000);
}
return this;
});
Using this template, you can set the callback function in a.js to handle the delayed response from b.js.
Hope this helps you.
source
share