From a06021d8b5d488cdef55916daba88b06ee215a91 Mon Sep 17 00:00:00 2001 From: Karl Seamon Date: Wed, 4 Dec 2013 16:02:28 -0500 Subject: [PATCH] chore(Angular.js): Use call and === instead of apply and == in type check functions Updates isDate et al to use call instead of apply and === instead of ==. The change to call brings minor performance improvement and === is just better practice than ==. http://jsperf.com/call-vs-apply-tostring --- src/Angular.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Angular.js b/src/Angular.js index 8ee08e4809c7..691ddbc66f66 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -393,7 +393,7 @@ function valueFn(value) {return function() {return value;};} * @param {*} value Reference to check. * @returns {boolean} True if `value` is undefined. */ -function isUndefined(value){return typeof value == 'undefined';} +function isUndefined(value){return typeof value === 'undefined';} /** @@ -407,7 +407,7 @@ function isUndefined(value){return typeof value == 'undefined';} * @param {*} value Reference to check. * @returns {boolean} True if `value` is defined. */ -function isDefined(value){return typeof value != 'undefined';} +function isDefined(value){return typeof value !== 'undefined';} /** @@ -422,7 +422,7 @@ function isDefined(value){return typeof value != 'undefined';} * @param {*} value Reference to check. * @returns {boolean} True if `value` is an `Object` but not `null`. */ -function isObject(value){return value != null && typeof value == 'object';} +function isObject(value){return value != null && typeof value === 'object';} /** @@ -436,7 +436,7 @@ function isObject(value){return value != null && typeof value == 'object';} * @param {*} value Reference to check. * @returns {boolean} True if `value` is a `String`. */ -function isString(value){return typeof value == 'string';} +function isString(value){return typeof value === 'string';} /** @@ -450,7 +450,7 @@ function isString(value){return typeof value == 'string';} * @param {*} value Reference to check. * @returns {boolean} True if `value` is a `Number`. */ -function isNumber(value){return typeof value == 'number';} +function isNumber(value){return typeof value === 'number';} /** @@ -465,7 +465,7 @@ function isNumber(value){return typeof value == 'number';} * @returns {boolean} True if `value` is a `Date`. */ function isDate(value){ - return toString.apply(value) == '[object Date]'; + return toString.call(value) === '[object Date]'; } @@ -481,7 +481,7 @@ function isDate(value){ * @returns {boolean} True if `value` is an `Array`. */ function isArray(value) { - return toString.apply(value) == '[object Array]'; + return toString.call(value) === '[object Array]'; } @@ -496,7 +496,7 @@ function isArray(value) { * @param {*} value Reference to check. * @returns {boolean} True if `value` is a `Function`. */ -function isFunction(value){return typeof value == 'function';} +function isFunction(value){return typeof value === 'function';} /** @@ -507,7 +507,7 @@ function isFunction(value){return typeof value == 'function';} * @returns {boolean} True if `value` is a `RegExp`. */ function isRegExp(value) { - return toString.apply(value) == '[object RegExp]'; + return toString.call(value) === '[object RegExp]'; } @@ -529,12 +529,12 @@ function isScope(obj) { function isFile(obj) { - return toString.apply(obj) === '[object File]'; + return toString.call(obj) === '[object File]'; } function isBoolean(value) { - return typeof value == 'boolean'; + return typeof value === 'boolean'; } @@ -638,7 +638,7 @@ function includes(array, obj) { function indexOf(array, obj) { if (array.indexOf) return array.indexOf(obj); - for ( var i = 0; i < array.length; i++) { + for (var i = 0; i < array.length; i++) { if (obj === array[i]) return i; } return -1;