typescript MyObject.instanceOf()
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: All of our typescript classes inherit (directly or indirectly) from: export class WrObject { className:string; public instanceOf(name : String) : boolean { return this.className === name; } } We then declare a subclass as: export class Section extends WrObject { public static CLASS_NAME = 'Section'; className = Section.CLASS_NAME; public instanceOf(name : String) : boolean { if (this.className === name) return true; return super.instanceOf(name); } } And you can then check with: if (obj.instanceOf(Section.CLASS_NAME)) It all works great.