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