I am trying to call a inherited method that must access private attributes from current object. But it only access the public ones, what is wrong?
My test code should alert both vars:
function ParentClass(){
//Priviliged method to show just attributes
this.priviligedMethod = function(){
for( var attr in this ){
if( typeof(this[ attr ]) !== 'function' ){
alert("Attribute: " + this[ attr ]);
}
}
};
}
function ChildClass(){
// Call the parent constructor
ParentClass.call(this);
var privateVar = "PRIVATE VAR";
this.publicVAR = "PUBLIC VAR";
}
// inherit from parent class
ChildClass.prototype = new ParentClass();
// correct the constructor pointer because it points to parent class
ChildClass.prototype.constructor = ChildClass;
var objChild = new ChildClass();
objChild.priviligedMethod();
The jsfiddle version: http://jsfiddle.net/gws5s/6/
Thanks in advance, Arthur