I structured my code with requireJS. In my init.js
require(["jquery", "user"], function($, user){
console.log(user.isLogin());
});
In my user.js
define(["jquery"], function($){
return{
isLogin: function(){
var status = 0;
function callApi(){
return $.ajax({
type: "post",
url: urls.api_isLogin,
dataType: "json"
}
callApi().done(function(data){
status = data.data;
console.log(status);
return status;
});
}
};
});
I can get the data from ajax call:
console.log(status);
//output: true
//means I can get the value from the ajax call
But how can I pass it into init.js?
I got "undefined" from:
console.log(user.isLogin());