This happens to be from a Chrome extension, but I believe this is a pertinent general JS question. I have a working func like so to access local storage:
function loadItem(sName, callback){
var get = {};
get[sName] = {}; //blank obj by default.
chrome.storage.local.get(get, function(data) {
data[sName] && callback(data[sName]);
});
};
When I invoke loadItem
's callback in an asynchronously-called "outer" callback, I make use of loadItem
's arg sName
. Why is that defined in there? Shouldn't the asynchronous callback not recognise that var because loadItem
has finished running and sName
was not provided as one of the callback's own args?