mercredi 25 mars 2015

returning results to outer function

Not quite sure how to return result to outer function, i want to call getListOfUsers() and get returned list of results





function getListOfUsers() {
userlist.getUsers(function(next, res) {
var result = JSON.parse(res);
var listOfUsers = result.members.map(function (mem) {
return mem.name;
});
});
}



If i return outside of the map, it will obviously return undefined, or null if i define it outside and initiate it inside. Using promises leaves me in same situation where my return is inside the 'then' function. Whats common practice here?


Aucun commentaire:

Enregistrer un commentaire