Javascript OOP return value from function

前端 未结 2 763
感动是毒
感动是毒 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);
    }
    

提交回复
热议问题