Files
lodash/_getFuncName.js
2017-01-09 12:20:58 -08:00

32 lines
766 B
JavaScript

import realNames from './_realNames.js';
/** Used for built-in method references. */
const objectProto = Object.prototype;
/** Used to check objects for own properties. */
const hasOwnProperty = objectProto.hasOwnProperty;
/**
* Gets the name of `func`.
*
* @private
* @param {Function} func The function to query.
* @returns {string} Returns the function name.
*/
function getFuncName(func) {
const result = `${ func.name }`;
const array = realNames[result];
let length = hasOwnProperty.call(realNames, result) ? array.length : 0;
while (length--) {
const data = array[length];
const otherFunc = data.func;
if (otherFunc == null || otherFunc == func) {
return data.name;
}
}
return result;
}
export default getFuncName;