javascript - Underscore templates failing with "unexpected identifier" in IE 8 - Stack Overflow

We have a BackboneMarionette web application. The application works fine in modern browsers but dies

We have a Backbone / Marionette web application. The application works fine in modern browsers but dies in IE8 with

SCRIPT1010: Expected identifier

The debugger points to a line deep in the Underscore.js library rather than in my code. Obviously there isn't a problem in the library - our code is triggering this problem. The line is this

var render = new Function(settings.variable || 'obj', '_', source);

What could the problem be?

We have a Backbone / Marionette web application. The application works fine in modern browsers but dies in IE8 with

SCRIPT1010: Expected identifier

The debugger points to a line deep in the Underscore.js library rather than in my code. Obviously there isn't a problem in the library - our code is triggering this problem. The line is this

var render = new Function(settings.variable || 'obj', '_', source);

What could the problem be?

Share Improve this question asked May 3, 2013 at 14:40 Rob MurphyRob Murphy 9538 silver badges14 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

It turned out this was a specific case in one of our template which meant when the template was piled, the code was fine in modern browsers but threw a wobbly in IE8.

We are passing data in from our view with some useful strings using the serializeData function like so (coffeescript but you get the idea):

...
serializeData: ->
   data = super()
   data.messages = {
      intro: "Wele to the app"
      continue: "Click here to continue"
   }
   return data
...

then referencing that in the template like so

<h1>{{ messages.intro }}</h1>
<a href="...">{{ messages.continue }}</h1>

The problem es from the fact that "continue" is a reserved word. Coffeescript is nice and allows you to use it as a key in an object definition without quoting, and it would appear that in regular JS in more modern browsers they're ok with using it unquoted (though one would generally remend to do so).

In IE8 however you may not set it like obj = { continue: "foo" } and you may not get it like obj.continue, it must be obj["continue"].

Replacing {{ messages.continue }} with {{ messages["continue"] }} or renaming the property fixed the issue.

Hope that helps someone :)

Rob

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742411074a4438823.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信