mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 01:57:50 +00:00
Add toSource helper.
This commit is contained in:
37
lodash.js
37
lodash.js
@@ -1449,11 +1449,11 @@
|
|||||||
var realNames = {};
|
var realNames = {};
|
||||||
|
|
||||||
/** Used to detect maps, sets, and weakmaps. */
|
/** Used to detect maps, sets, and weakmaps. */
|
||||||
var dataViewCtorString = DataView ? (DataView + '') : '',
|
var dataViewCtorString = toSource(DataView),
|
||||||
mapCtorString = Map ? funcToString.call(Map) : '',
|
mapCtorString = toSource(Map),
|
||||||
promiseCtorString = Promise ? funcToString.call(Promise) : '',
|
promiseCtorString = toSource(Promise),
|
||||||
setCtorString = Set ? funcToString.call(Set) : '',
|
setCtorString = toSource(Set),
|
||||||
weakMapCtorString = WeakMap ? funcToString.call(WeakMap) : '';
|
weakMapCtorString = toSource(WeakMap);
|
||||||
|
|
||||||
/** Used to convert symbols to primitives and strings. */
|
/** Used to convert symbols to primitives and strings. */
|
||||||
var symbolProto = Symbol ? Symbol.prototype : undefined,
|
var symbolProto = Symbol ? Symbol.prototype : undefined,
|
||||||
@@ -5290,7 +5290,7 @@
|
|||||||
getTag = function(value) {
|
getTag = function(value) {
|
||||||
var result = objectToString.call(value),
|
var result = objectToString.call(value),
|
||||||
Ctor = result == objectTag ? value.constructor : null,
|
Ctor = result == objectTag ? value.constructor : null,
|
||||||
ctorString = typeof Ctor == 'function' ? funcToString.call(Ctor) : '';
|
ctorString = toSource(Ctor);
|
||||||
|
|
||||||
if (ctorString) {
|
if (ctorString) {
|
||||||
switch (ctorString) {
|
switch (ctorString) {
|
||||||
@@ -5739,6 +5739,22 @@
|
|||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts `func` to its source code.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Function} func The function to process.
|
||||||
|
* @returns {string} Returns the source code.
|
||||||
|
*/
|
||||||
|
function toSource(func) {
|
||||||
|
if (isFunction(func)) {
|
||||||
|
try {
|
||||||
|
return funcToString.call(func);
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
return toString(func);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a clone of `wrapper`.
|
* Creates a clone of `wrapper`.
|
||||||
*
|
*
|
||||||
@@ -10842,13 +10858,10 @@
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (isFunction(value)) {
|
if (isObjectLike(value)) {
|
||||||
try {
|
return (isHostObject(value) ? reIsNative : reIsHostCtor).test(value);
|
||||||
return reIsNative.test(funcToString.call(value));
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
}
|
||||||
return isObjectLike(value) &&
|
return reIsNative.test(toSource(value));
|
||||||
(isHostObject(value) ? reIsNative : reIsHostCtor).test(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user