[]怎么获取完全限定类名,就像as的getQualifiedClassName

已邀请:

15068753667

赞同来自:

只限基于ActionScript的项目,基于ts的嗝屁
 const a = new Laya.Event()
Laya.__classmap['laya.events.Event'] == a.constructor //true
 

宇智波 旋

赞同来自:

/**返回指定对象的完全限定名 */
static getQualifiedClassName(value):string {
var type = typeof value;
if (!value || (type != "object" && !value.prototype)) {
return type;
}
var prototype = value.prototype ? value.prototype : Object.getPrototypeOf(value);
if (prototype.hasOwnProperty("__class__")) {
return prototype["__class__"];
}
var constructorString = prototype.constructor.toString().trim();
var index = constructorString.indexOf("(");
var className = constructorString.substring(9, index);
Object.defineProperty(prototype, "__class__", {
value: className,
enumerable: false,
writable: true
});
return className;

不用些谢 白鹭拷贝过来的代码 
 
 

孖孖

赞同来自:

calss.prototype.constructor.name; 或者 this.constructor.name;试一下?

cuixueying

赞同来自:

请参考:ClassUtils

要回复问题请先

商务合作
商务合作