Open GoogleCodeExporter opened 9 years ago
Hi,
the problem is the difference between Array and NodeList.
Each "document.getElementsByTagName('..')" returns a NodeList instead of an
Array.
To solve the problem convert the NodeList to an Array by adding the following
code:
-------------
var ary = [];
for(var i=0, len = object.length; i < len; i++) {
ary.push(object[i]);
}
object = ary;
-------------
at the end of the file in the globally resolve for forEach enumeration
Here the final result:
var forEach = function(object, block, context) {
if (object) {
var resolve = Object; // default
if (object instanceof Function) {
// functions have a "length" property
resolve = Function;
} else if (object.forEach instanceof Function) {
// the object implements a custom forEach method so use that
object.forEach(block, context);
return;
} else if (typeof object == "string") {
// the object is a string
resolve = String;
} else if (typeof object.length == "number") {
// the object is array-like
resolve = Array;
var ary = [];
for(var i=0, len = object.length; i < len; i++) {
ary.push(object[i]);
}
object = ary;
}
resolve.forEach(object, block, context);
}
}
Original comment by gerd.pir...@gmail.com
on 11 Nov 2009 at 2:00
Hi, thanks so much for you help. That solved my problem.
Original comment by calbu...@gmail.com
on 2 Dec 2009 at 1:34
Thanks a TON! Wondered about this error for a few days now.. what an easy
solution :-)
Original comment by Rwilson...@gmail.com
on 22 Apr 2011 at 7:55
Original issue reported on code.google.com by
calbu...@gmail.com
on 20 Oct 2009 at 4:13