Each function object should have two “hidden” properties ( per JavaScript The Good Parts, The Functions Chapter )
context
and
code
Is there a way to access these properties?
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.
Well, you can access the function code pretty easily – by using toString() (or Mozilla’s non-standard toSource()):
As for context, I suppose DC meant more than simple
this, and actually wrote about Execution Context.UPDATE: Have found an interesting snippet in ES5 specification, where these two properties are actually described in some details – and not as abstract concepts:
At the same time:
So I guess that closes the question about accessing
Scopeproperty of function.As for
Codeproperty, its read-only accessing withtoString(), as was rightly noticed by Matt, is implementation-dependent – yet is more often implemented than not. )