From b5fffe9c1e0b1c604014c11c48c8869e6668d97e Mon Sep 17 00:00:00 2001 From: Brook Zhou Date: Fri, 23 Oct 2015 06:32:51 -0700 Subject: [PATCH] Add support for resolving template functions using object prototype instead of current view object --- mustache.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mustache.js b/mustache.js index 18706ae..8776410 100644 --- a/mustache.js +++ b/mustache.js @@ -414,8 +414,13 @@ cache[name] = value; } - if (isFunction(value)) - value = value.call(this.view); + if (isFunction(value)){ + if (names && names.length > 1 && typeof Object.getPrototypeOf(names[names.length-2])[names[names.length-1]] === 'function'){ + value = value.call(names[names.length-2]); + } else { + value = value.call(this.view); + } + } return value; };