admin管理员组

文章数量:1336589

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

本文标签: javascriptUnderscore templates failing with quotunexpected identifierquot in IE 8Stack Overflow