简体   繁体   中英

variable gets assigned function

My English = Google Translate. Sorry :(

function XXX(){
    abc = function(){return 'Message';}
    return abc;
}

function Alerttt(){
    var AlertText= XXX();
    alert(AlertText);
}

Result:

AlertText = function(){return 'Message';}

I want to:

AlertText = Message

How can I do?

You'll have to call the function.

 function XXX() { abc = function() { return 'Message'; } return abc; } function Alerttt() { var AlertText = XXX(); alert(AlertText()); // call it } Alerttt(); 

You can also do var AlertText = XXX()(); so that AlertText gets the return value from the called function so you can just do alert(AlertText);

Are you looking for this?

 function XXX() { abc = function(){return 'Message';} return abc; } function Alerttt() { var AlertText = XXX()(); alert(AlertText); } Alerttt(); 

Calling XXX returns a function object, so XXX() is a function object, and you need to call that function object as XXX()() to return 'Message'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM