123456789101112131415161718192021222324252627282930313233343536373839404142 |
- 'use strict';
- var toString = Object.prototype.toString;
- module.exports = function name(fn) {
- if ('string' === typeof fn.displayName && fn.constructor.name) {
- return fn.displayName;
- } else if ('string' === typeof fn.name && fn.name) {
- return fn.name;
- }
-
-
-
- if (
- 'object' === typeof fn
- && fn.constructor
- && 'string' === typeof fn.constructor.name
- ) return fn.constructor.name;
-
-
-
-
- var named = fn.toString()
- , type = toString.call(fn).slice(8, -1);
- if ('Function' === type) {
- named = named.substring(named.indexOf('(') + 1, named.indexOf(')'));
- } else {
- named = type;
- }
- return named || 'anonymous';
- };
|