use its own destruct function (#16622)

This commit is contained in:
minggo
2023-12-19 11:29:27 +08:00
committed by GitHub
parent 92ea67eef3
commit 4cd8d65b98
+15 -6
View File
@@ -347,11 +347,14 @@ class CCObject implements EditorExtendableObject {
*/
public _destruct (): void {
const ctor: any = this.constructor;
let destruct = ctor.__destruct__;
if (!destruct) {
let destruct;
if (Object.prototype.hasOwnProperty.call(ctor, '__destruct__')) {
destruct = ctor.__destruct__;
} else {
destruct = compileDestruct(this, ctor);
js.value(ctor, '__destruct__', destruct, true);
}
destruct(this);
}
@@ -394,13 +397,16 @@ if (EDITOR || TEST) {
* This method is only available for editors and is not recommended for developers
* @zh 在继承 CCObject 对象后,控制是否需要隐藏,锁定,序列化等功能(该方法仅提供给编辑器使用,不建议开发者使用)。
*/
js.getset(prototype, 'objFlags',
js.getset(
prototype,
'objFlags',
function (this: CCObject) {
return this._objFlags;
},
function (this: CCObject, objFlags: CCObject.Flags) {
this._objFlags = objFlags;
});
},
);
/*
* @en
@@ -674,8 +680,11 @@ declare const jsb: any;
if (JSB) {
copyAllProperties(CCObject, jsb.CCObject, ['prototype', 'length', 'name']);
copyAllProperties(CCObject.prototype, jsb.CCObject.prototype,
['constructor', 'name', 'hideFlags', 'isValid']);
copyAllProperties(
CCObject.prototype,
jsb.CCObject.prototype,
['constructor', 'name', 'hideFlags', 'isValid'],
);
(CCObject as unknown as any) = jsb.CCObject;
}