HTML and CSS Reference
In-Depth Information
var result = [];
for (var property in object) {
assertEquals(3, result.length);
Both of these tests fail in all versions of Internet Explorer, including IE8;
result.length is 0. We can solve this issue by making a special case for
the non-enumerable properties on Object.prototype as well as Function.
prototype if the object in question inherits from it.
The tddjs.each method in Listing 7.12 can be used to loop properties of an
object, accounting for Internet Explorer's bug. When defined, the method attempts
to loop the properties of an object that shadows all the non-enumerable proper-
ties on Object.prototype as well as a function that shadows non-enumerable
properties on Function.prototype . Any property that does not show up in
the loop is remembered and looped explicitly inside the each function.
Listing 7.12 Looping properties with a cross-browser each method
tddjs.each = (function () {
// Returns an array of properties that are not exposed
// in a for-in loop on the provided object
function unEnumerated(object, properties) {
var length = properties.length;
for(vari=0;i<length; i++) {
object[properties[i]] = true;
var enumerated = length;
for (var prop in object) {
if (tddjs.isOwnProperty(object, prop)) {
enumerated -= 1;
object[prop] = false;
if (!enumerated) {
Search WWH ::

Custom Search