I have a javascript object defined as follows:
function SocialMiner() { var verbose=true; var profileArray=new Array(); var tabUrl; this.getTabUrl=function() { logToConsole("getTabUrl is called"); chrome.tabs.getSelected(null, function(tab) { tabUrl = tab.url; logToConsole(tabUrl); }); return tabUrl; } `
Then I call this function in SocialMiner ojbect as follows:
var pageUrl=miner.getTabUrl(); miner.logToConsole(pageUrl);
What is the reason that the first call to logToConsole successfully prints the URL, and the second is undefined. Am I not returning the same value from a function?
Update. This is how I defined logToConsole:
function logToConsole(text) { if (verbose) console.log(text); } this.logToConsole=logToConsole;
source share