Javascript – sifr 3 r436 javascript error in IE 8

internet-explorer-8javascriptsifr

I get this error in IE8:

Object doesn't support this property or method

on this line.

this.results.forEach(function(a){if(!a.views){a.views=0}})

I am new to sifr and fairly new to Javascript so I am not sure on what to do here. If someone could point me in a "helpful" direction that would be wonderful.

Best Answer

You don't get a forEach method on arrays in any version of IE so far. Array.prototype.forEach is an ECMA-262 Fifth Edition feature which you can't rely on being available: the browser support baseline is Third Edition, where there is no map, filter, forEach or even indexOf on arrays.

You can correct this by hacking the Array.prototype to add the method if you like. See MDC's code, for example. Or, if you are using the prototype library, as you seem to be, you can use .each, which hides the difference from you.

ECMA-262 is really hard to read; A useful place to look for the real supported-everywhere baseline for built-in types is in the old Netscape 4-era JavaScript reference. Ignore the DOM stuff which is best documented elsewhere, but it's good for the JavaScript built-in types.