通过obj.constructor.name获取当前实例对象的构造函数名;

function Person(name){
    this.name = name;
}

var lilei = new Person("Lilei");
lilei.constructor.name; // "Person"

[1,2,4].constructor.name; // "Array"
(function(){}.constructor.name); // "Function"
"hello".constructor.name; // "String"

 

相关文章:

  • 2021-07-21
  • 2022-12-23
  • 2021-05-27
  • 2021-05-17
  • 2021-07-18
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
相关资源
相似解决方案