verstecken von Methoden geht IMHO nur, in dem man die Kette für die Zeit des for in loops unterbricht, oder eben mit typeof() == "function" testet, was dann in etwa so aussieht:
PHP-Code:
function Semmel() {
this.class = "Semmel";
this.aufstriche = ["Butter","Marmelade","Nutella"];
}
Semmel.prototype.showAufstriche = function() {
trace ("------ aufstriche gefiltert -------");
for (var i in this.aufstriche) {
if (typeof(this.aufstriche[i]) != "function") {
trace ( i + " : " + this.aufstriche[i]);
}
}
trace ("------ aufstriche ungefiltert -------");
for (var i in this.aufstriche) {
trace ( i + " : " + this.aufstriche[i]);
}
var m = this.__proto__.__proto__;
trace ("------ nur eigene methoden von semmel -------");
this.__proto__.__proto__ = null;
for (var i in this) {
trace (i + " : " + this[i]);
}
this.__proto__.__proto__ = m;
trace ("------ keine methoden -------");
var m = this.__proto__;
this.__proto__ = null;
for (var i in this) {
trace (i + " : " + this[i]);
}
this.__proto__ = m;
trace ("------ alle methoden von semmel -------");
for (var i in this) {
trace (i + " : " + this[i]);
}
trace ("-------------");
}
Object.prototype.pollution = function(){
trace("don't do that");
for (i in this) {
trace(i + " : " + this[i]);
}
}
meineSemmel = new Semmel();
meineSemmel.showAufstriche();
pollution();
kiriko ....