How to pass function arguments to another function?

159 views Asked by At
function A(a,b){
return /*something*/
}

function B(){
var a = /*a from function A*/
var b = /*b from function A*/
return /*something*/ 
}

How to pass the arguments a and b from function A to function B ?

2

There are 2 answers

1
Meltinglava On

Make 2 global varialbes.

var c = 0
var d = 0
function A(a,b){
    c = a
    d = b
    return /*something*/
}

Be aware that this will not work if you are calling funtion A multiple times, before calling funtion B. http://www.w3schools.com/js/js_scope.asp

0
Serge insas On

why not something simple like this :

function A(a,b){
  a++;b++;// an example
  return [a,b];
}

function B(){
  var val = A(4,5);// a test value
  var a = val[0];
  var b = val[1];
  Logger.log(a+'  '+b);
  return /*something*/ 
}