I've been trying to figure out how to set the value from a callback to a variable so that I can call the variable and access the data rather than having to place all my code inside the callback function. I posted two examples one which works, and the second which does work and returns undefined. How can I make it so that the second example works?
Here is where I get my data.
var chromeApi = {
msg: function (callbacks) {
chrome.runtime.sendMessage({type: "settings"}, callbacks);
}
};
When I access the data from chromeApi
this way it works fine.
chromeApi.msg(function (response) {
console.log(response);
});
But I want to access it this way I get undefined. How can I make my code work to use this method?
var test = chromeApi.msg(function (response) {
return response;
});
console.log(test);