Given a function, I’d like to know whether it’s a developer-defined function or a built-in function provided by JavaScript engine. Is it possible?
For a developer-defined function, I’d like to trace its execution.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
valueOfmethod you mention in your own answer will not work as you mention it.The
Function.prototypedoesn’t have avalueOfmethod, it is inherited fromObject.prototypeand this method will simply return the same function object where you call it:I think you are confusing it with the toString method (or you are alerting the valueOf method call which causes on most browsers an implicit ToString conversion).
However, you can use the
toStringmethod directly on function objects, and in almost all implementations, will return you a string representation containing"[native code]"in its function body, I wouldn’t recommend it too much because, theFunction.prototype.toStringmethod is implementation dependent…Again I advise you that there are some browsers that will return different results when using the
toStringmethod on functions, for example, some Mobile browsers will return the same string for any function object.