I think the simplest way to check if the function is ES6 class is to check the result of .toString()
method. According to the es2015 spec:
The string representation must have the syntax of a FunctionDeclaration FunctionExpression, GeneratorDeclaration, GeneratorExpression, ClassDeclaration, ClassExpression, ArrowFunction, MethodDefinition, or GeneratorMethod depending upon the actual characteristics of the object
So the check function looks pretty simple:
function isClass(func) {
return typeof func === 'function'
&& /^classs/.test(Function.prototype.toString.call(func));
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…