Javascript Question

How to check if a variable is an ES6 class declaration?

I am exporting the following ES6 class from one module:

export class Thingy {
hello() {

world() {

And importing it from another module:

import {Thingy} from "thingy";

if (isClass(Thingy)) {
// Do something...

How can I check whether a variable is a class? Not a class instance, but a class declaration?

In other words, how would I implement the
function in the example above?


In ES6, there is no "class" when code is running, you just have a constructor function, or an object. So you could do

if (typeof Thingy === 'function'){
  // It's a function, so it definitely can't be an instance.
} else {
  // It could be anything other than a constructor

As long as you know for a fact that something is either an instance or a constructor.