0

Is there a way to get the source code of a function by using it's name in javacsript? I'm using the console and while like to see the source code of the function but can't find it. I can execute it in the console and typing only in the name returns the function object.

2
  • Are you trying to do this programmatically? Commented Aug 16, 2021 at 23:34
  • Look at Function.prototype.toString(). Commented Aug 16, 2021 at 23:36

2 Answers 2

3

If you log it with console.dir, at least in Chrome, you'll see an internal [[FunctionLocation]] property that's clickable. For example, Stack Exchange uses jQuery, so doing console.dir($) in the console shows:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

2

you could achieve that by printing the function name only without invoke it

function sum(x, y){
   return x + y;
}

console.log(sum)

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.