diff options
author | kpdecker <kpdecker@gmail.com> | 2013-11-05 18:07:33 -0600 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2013-11-05 18:07:33 -0600 |
commit | affbcbb79e30c3004dd3a2cc25d2ceaf0f55740f (patch) | |
tree | 42583da9ae38f15e04db8197e6948d7301751505 /lib/handlebars/utils.js | |
parent | 96a45a4a967e5d11afba9d2deb8fc77d0a0992f3 (diff) | |
download | handlebars.js-affbcbb79e30c3004dd3a2cc25d2ceaf0f55740f.zip handlebars.js-affbcbb79e30c3004dd3a2cc25d2ceaf0f55740f.tar.gz handlebars.js-affbcbb79e30c3004dd3a2cc25d2ceaf0f55740f.tar.bz2 |
Unify isArray/isFunction/toString implementations
Restores Array.isArray polyfill for all use cases.
Fixes #645
Diffstat (limited to 'lib/handlebars/utils.js')
-rw-r--r-- | lib/handlebars/utils.js | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js index 998c9ca..65e91f9 100644 --- a/lib/handlebars/utils.js +++ b/lib/handlebars/utils.js @@ -1,7 +1,5 @@ import SafeString from "./safe-string"; -var isArray = Array.isArray; - var escape = { "&": "&", "<": "<", @@ -26,6 +24,26 @@ export function extend(obj, value) { } } +export var toString = Object.prototype.toString; + +// Sourced from lodash +// https://github.com/bestiejs/lodash/blob/master/LICENSE.txt +var isFunction = function(value) { + return typeof value === 'function'; +}; +// fallback for older versions of Chrome and Safari +if (isFunction(/x/)) { + isFunction = function(value) { + return typeof value === 'function' && toString.call(value) === '[object Function]'; + }; +} +export var isFunction; + +export var isArray = Array.isArray || function(value) { + return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false; +}; + + export function escapeExpression(string) { // don't escape SafeStrings, since they're already safe if (string instanceof SafeString) { |