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 badges1 Answer
Reset to default 11It 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
版权声明:本文标题:javascript - Underscore templates failing with "unexpected identifier" in IE 8 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742411074a2469797.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论