IE 8: Lost Without a Map

On my current project we’ve been working heavily with backbone.js and underscore.js. We were recently bit by a bug where all of our automated tests in Firefox and our manual tests in Firefox and Chrome passed.

But, good ‘ol IE 8 raised nasty javascript errors.

We discovered the problem was a forgotten call to underscore the array returned by underscore’s filter method. IE 8 does not support the array extensions from Javascript 1.6 like all the other modern browsers. This compatibility chart shows what it’s missing.

# broken
_(candies).filter((candy) ->
  candy.isChocalate?  
).map (candy) ->
  candy.yummy()

# plays well with IE8
_(_(candies).filter((candy) ->
  candy.isChocalate?  
)).map (candy) ->
  candy.yummy()

# allows for more method chaining
_(candies).chain().filter((candy) ->
  candy.isChocalate?
).map((candy) ->
  candy.yummy()
).value()

If IE 8 is a target browser for your project, don’t forget to bring a map (from underscore.js).

Conversation
  • Jonathon Klobucar says:

    Thanks, this post saved me a lot of work on this exact error I was having in IE8.

  • Aleksey Kulikov says:

    Great article, you save my day! Thanks!

  • Tony Summerville says:

    Seriously, thank you! Been banging my head against the wall and this was the issue…

    • Shawn Anderson Shawn Anderson says:

      Thanks Tony,
      it’s amazing how easily this problem can slip into your code unnoticed for so long.

  • Comments are closed.