In ECMAScript 6 the typeof
of classes is, according to the specification, \'function\'
.
However also according to the specification you are
You can use new.target to determine whether whether its instantiated by ES6 class function or function constructor
class Person1 {
constructor(name) {
this.name = name;
console.log(new.target) // => // => [Class: Person1]
}
}
function Person2(){
this.name='cc'
console.log(new.target) // => [Function: Person2]
}