Possible Duplicate:
Can Read-Only Properties be Implemented in Pure JavaScript?
I have an Object that I only want to be defined when constructed. How can I prevent the Object reference from being changed?
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.
EDIT: This was writtent 10 years ago. I don’t consider this to be an up to date answer.
Realistically… by not overwriting it. You could always control access by wrapping it in an object that only offers GetObj with no SetObj, but of course, the wrapper is equally liable to overwriting, as are its "private" member properties that would be "hidden" via the GetObj method.
Actually, question is a dupe:
Can Read-Only Properties be Implemented in Pure JavaScript?
EDIT:
After reading http://javascript.crockford.com/private.html , it is possible to use closure to create variable references that are truely inaccessible from the outside world. For instance:
where the reference to obj in objectHider cannot be modified after object creation.
I’m trying to think of a practical use for this.