mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 09:47:48 +00:00
Fixes #372 -- preserve dynamic scope for _.template functions.
This commit is contained in:
@@ -93,6 +93,12 @@ $(document).ready(function() {
|
|||||||
var result = template({value: "<script>"});
|
var result = template({value: "<script>"});
|
||||||
equals(result, '<i><script></i>');
|
equals(result, '<i><script></i>');
|
||||||
|
|
||||||
|
var stooge = {
|
||||||
|
name: "Moe",
|
||||||
|
template: _.template("I'm <%= this.name %>")
|
||||||
|
};
|
||||||
|
equals(stooge.template(), "I'm Moe");
|
||||||
|
|
||||||
if (!$.browser.msie) {
|
if (!$.browser.msie) {
|
||||||
var fromHTML = _.template($('#template').html());
|
var fromHTML = _.template($('#template').html());
|
||||||
equals(fromHTML({data : 12345}).replace(/\s/g, ''), '<li>24690</li>');
|
equals(fromHTML({data : 12345}).replace(/\s/g, ''), '<li>24690</li>');
|
||||||
|
|||||||
@@ -915,7 +915,10 @@
|
|||||||
.replace(/\t/g, '\\t')
|
.replace(/\t/g, '\\t')
|
||||||
+ "');}return __p.join('');";
|
+ "');}return __p.join('');";
|
||||||
var func = new Function('obj', '_', tmpl);
|
var func = new Function('obj', '_', tmpl);
|
||||||
return data ? func(data, _) : function(data) { return func(data, _) };
|
if (data) return func(data, _);
|
||||||
|
return function(data) {
|
||||||
|
return func.call(this, data, _);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// The OOP Wrapper
|
// The OOP Wrapper
|
||||||
|
|||||||
Reference in New Issue
Block a user