I've written an app using Yeoman and backbone.js. At the top of every js file I have specified 'use strict';
and when I run my grunt tasks jshint does not encounter any errors.
I am able to build my app with grunt without issue however when I try to run the uglified js I get the following error:
Uncaught SyntaxError: Strict mode code may not include a with statement
I've searched the code base and the only things using a with statement is underscore.
I'm new to strict mode so I'm not sure how I can resolve this issue. Can I not use strict mode anywhere that I use an underscorejs function?
Thanks.
EDIT:
Given the code samples below (shortened for brevity). How could I change it to resolve this issue.
'use strict';
/*global, Backbone, JST*/
var MyView = Backbone.View.extend({
template: JST['app/scripts/templates/MyView.ejs'],
initialize: function()
{
this.render();
},
render : function()
{
this.$el.html(this.template(this.templateVariables()));
return this;
},
templateVariables: function()
{
return {var1 : 'Hello', var2 : 'World'};
}
});
in MyView.ejs
<p><%= var1 %><%= var2 %>!</p> //<p>Hello World!</p>
EDIT 2:
Using @mu is too shorts's answer below I discovered that the best way to resolve the calls to _.template that were giving me grief was change my grunt-JST task as follows:
jst: {
compile: {
options:
{
templateSettings:
{
variable: 'data'
}
},
files: {
'.tmp/scripts/templates.js': ['<%= yeoman.app %>/scripts/templates/*.ejs']
}
}
},
And then change each of my templates to use the <%= data.templateVariable %>
format.
May not apply to others, but I ran into this issue using Yeoman with Grunt and a Backbone generator so I can't be the only one.