Private, Public, and Priveleged
HTML
<dl>
<dt>Private method
<dd>method that cannot be accessed from outside the object
<dt>Public method
<dd>method that can be accessed from outside the object
<dt>Priveleged method
<dd>public method that has access to private members due to
being created inside the constructor and not just using
the prototype
</dl>
JavaScript
function Cat(name) {
this.getName = function() {
// priveleged method
return name;
}
this.setName = function(newName) {
// priveleged method
name = newName;
}
function privateMethod(){
// private method
}
}
Cat.prototype.speak = function(){
// public method`
console.log(this.getName() + ' says, "Meow!"');
}
var d = new Cat("Duncan");