Javascript OOP return value from function

前端 未结 2 721
感动是毒
感动是毒 2021-01-28 00:30

I have javascript object defined like this:

function SocialMiner() 
{


var verbose=true;

var profileArray=new Array();

var tabUrl;

this.getTabUrl=function()
         


        
相关标签:
2条回答
  • 2021-01-28 00:43

    In the second example, you are calling logToConsole as if it is a function of the miner object, which is is not.

    miner.logToConsole
    

    Edit

    Per comments about github example, this should make the logToConsole function par of the SocialMiner object. However, I didn't read the class thoroughly, so proceed with caution with regards to how it is intended to be used.

    this.logToConsole=function(text) 
    {
        if (verbose)
            console.log(text);
    }
    
    0 讨论(0)
  • 2021-01-28 00:51

    It appears that logToConsole is defined somewhere globally; in any case, it is not a member of our SocialMiner class. Try this:

    var pageUrl=miner.getTabUrl();
    logToConsole(pageUrl);
    
    0 讨论(0)
提交回复
热议问题