In this example:
var circle = {
radius : 9,
getArea : function()
{
return (this.radius * this.radius) * Math.PI;
}
};
from this page‘s Encapsulation topic, the getArea is private, how would be with it public?
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.
That’s not JSON notation, that’s JavaScript object literal notation. (JSON is a subset of object literal notation. It doesn’t allow functions, requires double quotes, and doesn’t support octal or hex.)
getAreaisn’t private, anything can call it. The page you quoted is simply incorrect. If you want patterns for truly private methods in JavaScript, here’s a roundup with desciptions of the various trade-offs (including the memory cost of the Crockford model, which is the most common form).