Is there a way to call \"public\" javascript functions from \"private\" ones within a class?
Check out the class below:
function Class()
{
this.p
torazaburo's answer is the best one, as it avoids creation of multiple copies of the private members. I'm surprised that Crockford doesn't mention it at all. Alternately, depending on the syntax you prefer for declaring public member functions, you could do this:
function Class()
{}
(function() {
var privateMethod = function(self) {
self.publicMethod();
};
Class.prototype.publicMethod = function() {
alert('hello');
};
Class.prototype.test = function() {
privateMethod(this);
};
}());