I have this code,
MyNameSpace.Crate = {
init: function (crateID) {
var crate = MyNameSpace.Crate.get(crateID);
MyNameSpace.Crate.processData(crate);
// do more with data
},
get: function (crateID) {
var url = root + "Crate/";
$.getJSON(url, {
crateID: crateID
})
.done(function (data) {
// return data
})
.fail(function (data) {
// do soemthing
});;
},
processData : function(){
// do something with data
},
so on..
}
What I want is to FIRST get data from MyNameSpace.Crate.get(crateID)
only then move forward to MyNameSpace.Crate.processData(crate);
and other methods. As you can see get
method is async so I am not sure how can I force my code flow to get crate from get method before moving any forward.
Edit
I can call processData
method in .done(... function but that is not I want to achieve, it will not let me follow object literal pattern, which is why question mentioned in comments is not helpful.