mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 08:07:50 +00:00
Add isNative.
This commit is contained in:
27
lodash.js
27
lodash.js
@@ -517,7 +517,7 @@
|
||||
clearTimeout = context.clearTimeout,
|
||||
floor = Math.floor,
|
||||
fnToString = Function.prototype.toString,
|
||||
getPrototypeOf = reNative.test(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
|
||||
getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
|
||||
hasOwnProperty = objectProto.hasOwnProperty,
|
||||
push = arrayRef.push,
|
||||
propertyIsEnumerable = objectProto.propertyIsEnumerable,
|
||||
@@ -530,18 +530,18 @@
|
||||
// IE 8 only accepts DOM elements
|
||||
try {
|
||||
var o = {},
|
||||
func = reNative.test(func = Object.defineProperty) && func,
|
||||
func = isNative(func = Object.defineProperty) && func,
|
||||
result = func(o, o, o) && func;
|
||||
} catch(e) { }
|
||||
return result;
|
||||
}());
|
||||
|
||||
/* Native method shortcuts for methods with the same name as other `lodash` methods */
|
||||
var nativeCreate = reNative.test(nativeCreate = Object.create) && nativeCreate,
|
||||
nativeIsArray = reNative.test(nativeIsArray = Array.isArray) && nativeIsArray,
|
||||
var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate,
|
||||
nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray,
|
||||
nativeIsFinite = context.isFinite,
|
||||
nativeIsNaN = context.isNaN,
|
||||
nativeKeys = reNative.test(nativeKeys = Object.keys) && nativeKeys,
|
||||
nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys,
|
||||
nativeMax = Math.max,
|
||||
nativeMin = Math.min,
|
||||
nativeParseInt = context.parseInt,
|
||||
@@ -729,7 +729,7 @@
|
||||
* @memberOf _.support
|
||||
* @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).
|
||||
@@ -1813,6 +1813,17 @@
|
||||
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.
|
||||
*
|
||||
@@ -2864,7 +2875,7 @@
|
||||
return false;
|
||||
}
|
||||
var valueOf = value.valueOf,
|
||||
objProto = typeof valueOf == 'function' && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
|
||||
objProto = isNative(valueOf) && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
|
||||
|
||||
return objProto
|
||||
? (value == objProto || getPrototypeOf(value) == objProto)
|
||||
@@ -6336,7 +6347,7 @@
|
||||
* _.defer(function() { console.log(_.now() - stamp); });
|
||||
* // => 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();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user