const MyClass = class Me { getClassName() { return Me.name; } }; 获取函数名 Object.getOwnPropertyNames(api.prototype)[1]; 获取函数和类名 /** * Gets the classname of an object or function if it can. Otherwise returns the provided default. * * Getting the name of a function is not a standard feature, so while this will work in many * cases, it should not be relied upon except for informational messages (e.g. logging and Error * messages). * * @private */ function className(object, defaultName) { var nameFromToStringRegex = /^function\s?([^\s(]*)/; var result = ""; if (typeof object === 'function') { result = object.name || object.toString().match(nameFromToStringRegex)[1]; } else if (typeof object.constructor === 'function') { result = className(object.constructor, defaultName); } return result || defaultName; } 扩展阅读 在Javascript中获取class的类型名的方法