How to return values in javascript

后端 未结 8 2056
孤独总比滥情好
孤独总比滥情好 2020-11-27 04:47

I have a javascript function:

function myFunction(value1,value2,value3)
{
     //Do stuff and 

     value2=somevalue2 //to return
     value3=somevalue3 //t         


        
8条回答
  •  不知归路
    2020-11-27 05:27

    I would prefer a callback solution: Working fiddle here: http://jsfiddle.net/canCu/

    function myFunction(value1,value2,value3, callback) {
    
        value2 = 'somevalue2'; //to return
        value3 = 'somevalue3'; //to return
    
        callback( value2, value3 );
    
    }
    
    var value1 = 1;
    var value2 = 2;
    var value3 = 3;
    
    myFunction(value1,value2,value3, function(value2, value3){
        if (value2 && value3) {
            //Do some stuff
            alert( value2 + '-' + value3 );
        }    
    });
    

提交回复
热议问题