I have a backbone / underscore application running through require.js
I have just been doing some cross browser checking on my application and realise that my applcation is having problems loading in the templates in ie8.
within my application and within the view part when the render function is run I load and call in the correct template
I then use _.template to transform the code.
so within render i call this
$t.$el.append($t.renderTemplate(data, templateVars));
data is the html in <%=%> format and templateVars is a list of objects which is returned data (normally json results)
the renderTemplate function looks like
renderTemplate: function(html, vars) {
var compiled = _.template(html);
console.log(compiled, "compiled");
return compiled(vars);
},
the problem is that in ie8 I get an error which is
Object doesn't support this property or method
this is the line its erroring out on
return render.call(this, data, _);
from this code
_.template = function(text, data, settings) {
settings = _.extend(_.templateSettings, settings);
// Compile the template source, taking care to escape characters that
// cannot be included in a string literal and then unescape them in code
// blocks.
var source = "__p+='" + text
.replace(escaper, function(match) {
return '\\' + escapes[match];
})
.replace(settings.escape || noMatch, function(match, code) {
return "'+\n_.escape(" + unescape(code) + ")+\n'";
})
.replace(settings.interpolate || noMatch, function(match, code) {
return "'+\n(" + unescape(code) + ")+\n'";
})
.replace(settings.evaluate || noMatch, function(match, code) {
return "';\n" + unescape(code) + "\n;__p+='";
}) + "';\n";
// If a variable is not specified, place data values in local scope.
if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
source = "var __p='';" +
"var print=function(){__p+=Array.prototype.join.call(arguments, '')};\n" +
source + "return __p;\n";
var render = new Function(settings.variable || 'obj', '_', source);
if (data) return render(data, _);
var template = function(data) {
return render.call(this, data, _);
};
// Provide the compiled function source as a convenience for build time
// precompilation.
template.source = 'function(' + (settings.variable || 'obj') + '){\n' +
source + '}';
return template;
};
// Add a "chain" function, which will delegate to the wrapper.
_.chain = function(obj) {
return _(obj).chain();
};
this is the code ff/chrome uses to convert pass back the template
// Add a "chain" function, which will delegate to the wrapper.
_.chain = function(obj) {
return _(obj).chain();
};
Underscore.js 1.3.2
this works fine in ie9, FF and chrome
can anyone help?