getFuncName.js 542 B

12345678910111213141516171819202122232425
  1. var realNames = require('./realNames');
  2. /**
  3. * Gets the name of `func`.
  4. *
  5. * @private
  6. * @param {Function} func The function to query.
  7. * @returns {string} Returns the function name.
  8. */
  9. function getFuncName(func) {
  10. var result = (func.name + ''),
  11. array = realNames[result],
  12. length = array ? array.length : 0;
  13. while (length--) {
  14. var data = array[length],
  15. otherFunc = data.func;
  16. if (otherFunc == null || otherFunc == func) {
  17. return data.name;
  18. }
  19. }
  20. return result;
  21. }
  22. module.exports = getFuncName;