1

I am wondering if it is possible to pass the name of a function as a parameter, but have a class then call that function. I am aware that you can pass functions as parameters, but that is not what I am curious about. Below is an example of what I am looking for.

function passFunction ( functionName ) {

   exampleClass.functionName();
   // Do Something With result
}

1 Answer 1

1

Like:

exampleClass[functionName]()

but be sure to check its a function first

if (typeof exampleClass[functionName] === 'function')
  exampleClass[functionName]()
Sign up to request clarification or add additional context in comments.

1 Comment

Sweet! This is exactly what I needed. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.