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

后端 未结 4 2076
甜味超标
甜味超标 2020-12-11 00:09

I am exporting the following ES6 class from one module:

export class Thingy {
  hello() {
    console.log(\"A\");
  }

  world() {
    console.log(\"B\");
           


        
4条回答
  •  渐次进展
    2020-12-11 00:35

    Maybe this can help

    let is_class = (obj) => {
        try {
            new obj();
            return true;
        } catch(e) {
            return false;
        };
    };
    

提交回复
热议问题