I’m 99.9% positive that this isn’t possible, but there may be some obscure ecmascript function I don’t know of in JS1.9 or something.
Does anyone know of any way to get the this object of the calling function?
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.
If what you’re really trying to do here is control access to your member variables and thus your question is really: “How do I restrict access to member variables?”, then maybe you would benefit from reading this article “Private Members in Javascript“. It’s possible, but since it isn’t a built-in language feature, it requires a particular style of coding your classes and methods to make it work.
I’m not an expert on this, but I think it uses a closure of the constructor to control access. Methods declared inside the constructor will have access to instance variables declared in the constructor. Any caller from outside the constructor will not (whether those other callers are other methods, derived class methods or outside callers).