Add isNative.

This commit is contained in:
John-David Dalton
2013-11-29 18:47:25 -06:00
parent 097a2f6582
commit 4590be7b65

View File

@@ -517,7 +517,7 @@
clearTimeout = context.clearTimeout, clearTimeout = context.clearTimeout,
floor = Math.floor, floor = Math.floor,
fnToString = Function.prototype.toString, fnToString = Function.prototype.toString,
getPrototypeOf = reNative.test(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf, getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
hasOwnProperty = objectProto.hasOwnProperty, hasOwnProperty = objectProto.hasOwnProperty,
push = arrayRef.push, push = arrayRef.push,
propertyIsEnumerable = objectProto.propertyIsEnumerable, propertyIsEnumerable = objectProto.propertyIsEnumerable,
@@ -530,18 +530,18 @@
// IE 8 only accepts DOM elements // IE 8 only accepts DOM elements
try { try {
var o = {}, var o = {},
func = reNative.test(func = Object.defineProperty) && func, func = isNative(func = Object.defineProperty) && func,
result = func(o, o, o) && func; result = func(o, o, o) && func;
} catch(e) { } } catch(e) { }
return result; return result;
}()); }());
/* Native method shortcuts for methods with the same name as other `lodash` methods */ /* Native method shortcuts for methods with the same name as other `lodash` methods */
var nativeCreate = reNative.test(nativeCreate = Object.create) && nativeCreate, var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate,
nativeIsArray = reNative.test(nativeIsArray = Array.isArray) && nativeIsArray, nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray,
nativeIsFinite = context.isFinite, nativeIsFinite = context.isFinite,
nativeIsNaN = context.isNaN, nativeIsNaN = context.isNaN,
nativeKeys = reNative.test(nativeKeys = Object.keys) && nativeKeys, nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys,
nativeMax = Math.max, nativeMax = Math.max,
nativeMin = Math.min, nativeMin = Math.min,
nativeParseInt = context.parseInt, nativeParseInt = context.parseInt,
@@ -729,7 +729,7 @@
* @memberOf _.support * @memberOf _.support
* @type boolean * @type boolean
*/ */
support.funcDecomp = !reNative.test(context.WinRTError) && reThis.test(runInContext); support.funcDecomp = !isNative(context.WinRTError) && reThis.test(runInContext);
/** /**
* Detect if `Function#name` is supported (all but IE). * Detect if `Function#name` is supported (all but IE).
@@ -1813,6 +1813,17 @@
return result; return result;
} }
/**
* Checks if `value` is a native function.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is a native function, else `false`.
*/
function isNative(value) {
return typeof value == 'function' && reNative.test(value);
}
/** /**
* Sets `this` binding data on a given function. * Sets `this` binding data on a given function.
* *
@@ -2864,7 +2875,7 @@
return false; return false;
} }
var valueOf = value.valueOf, var valueOf = value.valueOf,
objProto = typeof valueOf == 'function' && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto); objProto = isNative(valueOf) && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
return objProto return objProto
? (value == objProto || getPrototypeOf(value) == objProto) ? (value == objProto || getPrototypeOf(value) == objProto)
@@ -6336,7 +6347,7 @@
* _.defer(function() { console.log(_.now() - stamp); }); * _.defer(function() { console.log(_.now() - stamp); });
* // => logs the number of milliseconds it took for the deferred function to be called * // => logs the number of milliseconds it took for the deferred function to be called
*/ */
var now = reNative.test(now = Date.now) && now || function() { var now = isNative(now = Date.now) && now || function() {
return new Date().getTime(); return new Date().getTime();
}; };