Not sure how to title this problem, but I'm trying to return an object and RequireJS doesn't wait for the asynchronous function to finish:
define([
"d3"
],
function(
d3
) {
var helper = {};
helper.foo = function() {
return "bar";
}
helper.bar = "hey!";
d3.json("/data/my_data.json", function(json) {
helper.data = json;
return helper;
});
// return helper;
});
Now if I use helper
in another script then it's undefined. If I move the return helper
outside the d3.json()
function (comment the first return and uncomment the second) then helper.foo
and helper.bar
is defined, but helper.data
is undefined.
What is the best way to make RequireJS return helper.data
?