1

Can some one explain me what can be use case of function's name property in Javascript?, I read that it can be helpful in recursion, how ?

function foo() {}
foo.name; // "foo"

2 Answers 2

3

a use case from MDN

You can use obj.constructor.name to check the "class" of an object

function a(){
}

var b = new a();
alert(b.constructor.name); //Alerts "a"

Think of it the as using get_class() in PHP or .getClass().getName() in Java.

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

Comments

1

I can't think of much of a use case, as it's read only. But it is described on MDN: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/name

I can only imagine you might want to use it in eval type situations.

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.