Javascript 如何检查javascript中的类是否存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4314084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 11:51:43  来源:igfitidea点击:

How to check if a class in javascript exists

javascript

提问by vikmalhotra

I am defining a class in javascript using this...

我正在使用这个在javascript中定义一个类......

// file_a.js
function class_a() {
    this.prop1 = null;
    this.prop2 = null;
}

// file_b.js
var obj = new class_a;
// I need to check here if class_a exists

How can I do this?

我怎样才能做到这一点?

Regards

问候

回答by Quentin

if (typeof class_a === 'function')