From 252aef9237552d2290b251679fed7d41f301134e Mon Sep 17 00:00:00 2001 From: Dan VerWeire Date: Wed, 6 Aug 2014 22:26:16 -0400 Subject: [PATCH] Use locals as `this` value inside filter functions This little patch changes the value of `this` inside all filter functions to that of the `locals` object. Currently it seems that `this` is a reference to the `filters` object. The purpose is to expose additional data to the filter function without having to pass additional arguments from the template. This could potentially be a breaking change if users are currently relying on `this` being a reference to the `filters` object from within their custom filters. Additional changes could be relatively easily made to make this configurable. --- lib/ejs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ejs.js b/lib/ejs.js index ca304a13..7ce6a034 100644 --- a/lib/ejs.js +++ b/lib/ejs.js @@ -56,7 +56,7 @@ function filtered(js) { , name = parts.shift() , args = parts.join(':') || ''; if (args) args = ', ' + args; - return 'filters.' + name + '(' + js + args + ')'; + return 'filters.' + name + '.call(locals,' + js + args + ')'; }); };