5 Comments

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).