This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
js wtfs
oatkiller edited this page Sep 13, 2010
·
4 revisions
undefined members arent iterated in for in loops in ie :(
(function () {
var how_many_iterations_and_members = function (obj) {
var iteration_count = 0, member_count = 0;
for (property_name in obj) {
iteration_count++;
if (obj.hasOwnProperty(property_name)) {
member_count++;
}
}
return {
member_count: member_count,
iteration_count: iteration_count
};
};
var data = how_many_iterations_and_members({'0': undefined, '1': undefined, '2': undefined});
// true in ie
Assert.areSame(3,data.member_count,'shouldve found 3 members in the obj');
// true in ie
Assert.areSame(3,data.iteration_count,
'shouldve iterated a total of 3 times, since this obj should have nothing in its prototype (kinda)');
var data = how_many_iterations_and_members([undefined,undefined,undefined]);;
// false in ie, finds 0
Assert.areSame(3,data.member_count,'it shouldve found 3 members in the arrray');
// false in ie, it doesnt event iterate over these in a for (propertyname in obj) loop
Assert.isTrue(data.iteration_count > how_many_iterations_and_members([]).iteration_count,
'it shouldve iterated more than just the same amount it would in an empty array');
})();