views:

69

answers:

3

When I run the following javascript in IE, I get "Error: Object doesn't support this property or method" on "data.every(...)".

It works in Chrome/Firefox.

alt text

+6  A: 

There's no every method defined in jQuery. You could use each instead:

$.each(data, function(index, task) {
    createCardFromTask(task);
});

or a little shorter:

$.each(data, function() {
    createCardFromTask(this);
});
Darin Dimitrov
+1 - `$.each()` is definitely the way to go for this simple of a callback function...
gnarf
+5  A: 

.every() is a JavaScript 1.6 enhancement to the Array prototype. Firefox supports this method in Gecko 1.8b2 and later, and here is a quick replacement if it doesn't exist.

From MDC:

every is a recent addition to the ECMA-262 standard; as such it may not be present in all browsers. You can work around this by inserting the following code at the beginning of your scripts, allowing use of every in implementations which do not natively support it. This algorithm is exactly the one used in Firefox and SpiderMonkey.

if (!Array.prototype.every)
{
  Array.prototype.every = function(fun /*, thisp*/)
  {
    var len = this.length >>> 0;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this &&
          !fun.call(thisp, this[i], i, this))
        return false;
    }

    return true;
  };
}
gnarf
Why the `this.length >>> 0`? Does it do anything other than returning this.length?
Krab
That was copied from the MDC Article... `this.length >>> 0` is a unsigned bitshift, the only reason I could think to add that is to make sure `length` is an unsigned number *shrug*
gnarf
A: 

I recently had the same problem with .each function when I tried to loop through selection of DOM elements. Turns out the problem wasn't with Javascript. It was the HTML, a special tag we were using. ABBR, isn't supported by IE6.

I suggest you first check all your tags, make sure all tags are supported by IE6.

Darkerstar