0
function secondFunctionName(){
  return value;
}

function functionName( parameter){
   // do something with the parameter
}

<input onclick="functionName(secondFunctionName)" />
  1. My question is how to pass secondFunctionName() as a parameter of functionName()

  2. what if function secondFunctionName() has parameters e.g. function secondFunctionName(data), how to do that?

Joey
  • 2,732
  • 11
  • 43
  • 63
  • Just as an aside - once you start messing around with functions as parameters, you might want to start looking into closures too. –  Jul 28 '14 at 19:56

2 Answers2

0

You can do that using straight JavaScript quite easily -

var secondFunctionName = function(){
  return value;
}

function functionName( parameter){
    // do something with the parameter
    var myValue = parameter();
}

<input onclick="functionName(secondFunctionName)" />

You will have to invoke that function in your functionName, however.

0

if your going to use returned value of a function into another function same as an argument
I think there is just one way to do that and I hope it help's you

function functionOne(){
   return value;
}
var result = functionOne();
function functionTwo(result){
   // do something with the parameter
}

or i think this one shoud work too

function functionOne(){
   return value;
}
function functionTwo(functionOne()){
   // do something with the parameter
}
mk rowling
  • 203
  • 1
  • 12
  • Regarding the second - that will work, but it really doesn't pass the function as a parameter. All you are doing is evaluating that function call and using the result. –  Jul 28 '14 at 19:58