können also sagen, ich habe einige Prototyp Methoden der Array-Klasse hinzugefügt:Javascript: Verbergen von Prototyp-Methoden in for-Schleife?
Array.prototype.containsKey = function(obj) {
for(var key in this)
if (key == obj) return true;
return false;
}
Array.prototype.containsValue = function(obj) {
for(var key in this)
if (this[key] == obj) return true;
return false;
}
dann erstelle ich ein assoziatives Array und versuchen, Schleife durch sie die Tasten:
var arr = new Array();
arr['One'] = 1;
arr['Two'] = 2;
arr['Three'] = 3;
for(var key in arr)
alert(key);
diese fünf Elemente zurückgibt:
-One -Two -Three -containsKey -containsValue
aber ich will (erwarten?) Nur drei. Komme ich mir das falsch? Gibt es eine Möglichkeit, die prototypischen Methoden zu "verstecken"? oder sollte ich etwas anders machen?
Siehe auch [diese Antwort] (http://stackoverflow.com/a/13296897/1048572) – Bergi