Skip to content

Commit 2bc29ec

Browse files
committed
Prevent global var leak
Also, changed order of arguments to internal render function.
1 parent e45bbb3 commit 2bc29ec

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

mustache.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ var Mustache;
229229
}
230230
}
231231

232-
return fn(Context.make(view), self, template);
232+
return fn(self, Context.make(view), template);
233233
};
234234
}
235235

@@ -245,13 +245,13 @@ var Mustache;
245245
var buffer = "";
246246

247247
for (var i = 0, len = value.length; i < len; ++i) {
248-
buffer += callback(context.push(value[i]), this);
248+
buffer += callback(this, context.push(value[i]));
249249
}
250250

251251
return buffer;
252252
}
253253

254-
return value ? callback(context.push(value), this) : "";
254+
return value ? callback(this, context.push(value)) : "";
255255
case "function":
256256
var self = this;
257257
var scopedRender = function (template) {
@@ -261,7 +261,7 @@ var Mustache;
261261
return value.call(context.view, text, scopedRender) || "";
262262
default:
263263
if (value) {
264-
return callback(context, this);
264+
return callback(this, context);
265265
}
266266
}
267267

@@ -274,7 +274,7 @@ var Mustache;
274274
// Use JavaScript's definition of falsy. Include empty arrays.
275275
// See https://github.com/janl/mustache.js/issues/186
276276
if (!value || (isArray(value) && value.length === 0)) {
277-
return callback(context, this);
277+
return callback(this, context);
278278
}
279279

280280
return "";
@@ -328,16 +328,17 @@ var Mustache;
328328
function subRender(i, tokens, template) {
329329
if (!subRenders[i]) {
330330
var render = compileTokens(tokens);
331-
subRenders[i] = function (context, writer) {
332-
return render(context, writer, template);
331+
subRenders[i] = function (writer, context) {
332+
return render(writer, context, template);
333333
};
334334
}
335335

336336
return subRenders[i];
337337
}
338338

339-
function renderFunction(context, writer, template) {
340-
var buffer = [], text;
339+
function renderFunction(writer, context, template) {
340+
var buffer = [];
341+
var token, text;
341342

342343
for (var i = 0, len = tokens.length; i < len; ++i) {
343344
token = tokens[i];

0 commit comments

Comments
 (0)