Replace some _.isFunction checks with simple typeof checks and replace some typeof checks with _.isFunction checks based on likelihood of a problem value older enviros being passed.

This commit is contained in:
jdalton
2015-02-07 09:45:11 -08:00
parent 2a86f0776c
commit af02a1e024

View File

@@ -1907,7 +1907,7 @@
* @returns {number} Returns the timer id. * @returns {number} Returns the timer id.
*/ */
function baseDelay(func, wait, args, fromIndex) { function baseDelay(func, wait, args, fromIndex) {
if (!isFunction(func)) { if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
return setTimeout(function() { func.apply(undefined, baseSlice(args, fromIndex)); }, wait); return setTimeout(function() { func.apply(undefined, baseSlice(args, fromIndex)); }, wait);
@@ -3331,7 +3331,7 @@
*/ */
function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) { function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
var isBindKey = bitmask & BIND_KEY_FLAG; var isBindKey = bitmask & BIND_KEY_FLAG;
if (!isBindKey && !isFunction(func)) { if (!isBindKey && typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
var length = partials ? partials.length : 0; var length = partials ? partials.length : 0;
@@ -6655,8 +6655,8 @@
* // => logs 'done saving!' after the two async saves have completed * // => logs 'done saving!' after the two async saves have completed
*/ */
function after(n, func) { function after(n, func) {
if (!isFunction(func)) { if (typeof func != 'function') {
if (isFunction(n)) { if (typeof n == 'function') {
var temp = n; var temp = n;
n = func; n = func;
func = temp; func = temp;
@@ -6714,8 +6714,8 @@
*/ */
function before(n, func) { function before(n, func) {
var result; var result;
if (!isFunction(func)) { if (typeof func != 'function') {
if (isFunction(n)) { if (typeof n == 'function') {
var temp = n; var temp = n;
n = func; n = func;
func = temp; func = temp;
@@ -7037,7 +7037,7 @@
maxWait = false, maxWait = false,
trailing = true; trailing = true;
if (!isFunction(func)) { if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
wait = wait < 0 ? 0 : wait; wait = wait < 0 ? 0 : wait;
@@ -7322,7 +7322,7 @@
* // => { 'user': 'barney' } * // => { 'user': 'barney' }
*/ */
function memoize(func, resolver) { function memoize(func, resolver) {
if (!isFunction(func) || (resolver && !isFunction(resolver))) { if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
var memoized = function() { var memoized = function() {
@@ -7360,7 +7360,7 @@
* // => [1, 3, 5] * // => [1, 3, 5]
*/ */
function negate(predicate) { function negate(predicate) {
if (!isFunction(predicate)) { if (typeof predicate != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
return function() { return function() {
@@ -7540,7 +7540,7 @@
var leading = true, var leading = true,
trailing = true; trailing = true;
if (!isFunction(func)) { if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
if (options === false) { if (options === false) {
@@ -8818,12 +8818,12 @@
var Ctor = object.constructor, var Ctor = object.constructor,
index = -1, index = -1,
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto, proto = (isFunction(Ctor) && Ctor.prototype) || objectProto,
isProto = proto === object, isProto = proto === object,
result = Array(length), result = Array(length),
skipIndexes = length > 0, skipIndexes = length > 0,
skipErrorProps = support.enumErrorProps && (object === errorProto || object instanceof Error), skipErrorProps = support.enumErrorProps && (object === errorProto || object instanceof Error),
skipProto = support.enumPrototypes && typeof object == 'function'; skipProto = support.enumPrototypes && isFunction(object);
while (++index < length) { while (++index < length) {
result[index] = (index + ''); result[index] = (index + '');
@@ -9137,7 +9137,7 @@
if (isArr) { if (isArr) {
accumulator = isArray(object) ? new Ctor : []; accumulator = isArray(object) ? new Ctor : [];
} else { } else {
accumulator = baseCreate(typeof Ctor == 'function' && Ctor.prototype); accumulator = baseCreate(isFunction(Ctor) && Ctor.prototype);
} }
} else { } else {
accumulator = {}; accumulator = {};