PDA

Просмотр полной версии : Почему у ассоциативных массивов нет length


chingachgoog
01.08.2007, 14:00
Например, нельзя напрямую посмотреть число атрибутов у xml узла:


trace(мойXML.childNodes[0].attributes.length) // выводит undefined


Только опосредовано:


t=0
for (i in мойXML.childNodes[0].attributes){
trace ("i "+i+" "+xmlData.childNodes[0].attributes[i])
t++
}
trace(t)


Или все же можно?

iNils
01.08.2007, 14:09
Ассоциативный массив это Object, а у него нет свойства length.

etc
01.08.2007, 14:21
Если очень хочется:

__get__attributesLength = function() {
var i = 0;
for (var j in this.attributes) {
i++;
}
return i;
}
XMLNode.prototype.addProperty('attributesLength', __get__attributesLength, null);
xml = new XML('<node param="1" param2="2"/>');
trace(xml.firstChild.attributesLength);

chingachgoog
01.08.2007, 20:26
спасибо, теперь все стало на свои места