Unify isArray/isFunction/toString implementations

Restores Array.isArray polyfill for all use cases.

Fixes #645
This commit is contained in:
kpdecker
2013-11-05 18:07:33 -06:00
parent 96a45a4a96
commit affbcbb79e
2 changed files with 23 additions and 19 deletions
+3 -17
View File
@@ -12,25 +12,11 @@ export var REVISION_CHANGES = {
4: '>= 1.0.0'
};
var toString = Object.prototype.toString,
var isArray = Utils.isArray,
isFunction = Utils.isFunction,
toString = Utils.toString,
objectType = '[object Object]';
// 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]';
};
}
function isArray(value) {
return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false;
}
export function HandlebarsEnvironment(helpers, partials) {
this.helpers = helpers || {};
this.partials = partials || {};
+20 -2
View File
@@ -1,7 +1,5 @@
import SafeString from "./safe-string";
var isArray = Array.isArray;
var escape = {
"&": "&",
"<": "&lt;",
@@ -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) {