In the Java Programming language the private keyword is used for data hiding – a field or a method marked as private is not visible outside the classes or the subclasses.
How is that achieved in javascript?
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.
In JavaScript standard way is to use Module Pattern as shown below..
Usage: In the above code an object is returned which contains a variable (myPublicVar) and a function(myPublicFunction). Inside this function you can access the inner variable (myPrivateVar) and inner function(myPrivateMethod) but not from outside.