3

Some functions are set into variables. And I want to debug what kind of function is set there? However that function can non be changed. In this situation, how should I debug?

var something = returnfunc(); //returnfunc() return function type object
console.log(something);

[Function]
2
  • 2
    What's the actual issue? There isn't different types of functions, all functions are just functions. Commented Apr 21, 2017 at 16:56
  • Maybe instead of returnfunc() you should be writing returnfunc without brackets. And returnfunc should be the function you are expecting. Commented Apr 21, 2017 at 16:59

3 Answers 3

2

You can call toString in the function to get a string representation of the source code ;)

E.g.:

let fn = (a, b) => a + b; 
console.log(fn.toString())
// (a, b) => a + b
Sign up to request clarification or add additional context in comments.

Comments

0

Maybe you meant check type of object that has value of function:

var something = returnfunc;
console.log(typeof something);

Comments

0

I think you're asking how to identify the function returned by returnfunc. If you use an anonymous function, it is harder to debug because that function is not identified with a name:

function returnfunc () {
  return function () {
    return 'I am an anonymous function'
  }
}

var fn = returnfunc() // [Function]

But you can just give the function a name:

function returnfunc () {
  return function foo () {
    return 'I am a named function'
  }
}

var fn = returnfunc() // [Function: foo]

Comments

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.