From 86fd5b59d676d82bcf6ceca70c325cff83b484cc Mon Sep 17 00:00:00 2001 From: "jiaxin.lai" Date: Thu, 16 Apr 2020 16:39:54 +0800 Subject: [PATCH] fix replace property (#6566) --- cocos/core/utils/deprecated.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cocos/core/utils/deprecated.ts b/cocos/core/utils/deprecated.ts index 13503ffaad..a70129e323 100644 --- a/cocos/core/utils/deprecated.ts +++ b/cocos/core/utils/deprecated.ts @@ -91,6 +91,7 @@ replaceProperty = (owner: object, ownerName: string, properties: IReplacement[]) const target = item.target != null ? item.target : owner; const newName = item.newName != null ? item.newName : item.name; const targetName = item.targetName != null ? item.targetName : ownerName; + const sameTarget = target == owner; if (item.customFunction != null) { owner[item.name] = function (this: any) { @@ -130,11 +131,15 @@ replaceProperty = (owner: object, ownerName: string, properties: IReplacement[]) Object.defineProperty(owner, item.name, { get (this) { replacePropertyLog(ownerName, item.name, targetName, newName, warn, id); - return this[newName]; + return sameTarget ? this[newName] : target[newName]; }, set (this, v: any) { replacePropertyLog(ownerName, item.name, targetName, newName, warn, id); - this[newName] = v; + if (sameTarget) { + this[newName] = v; + } else { + target[newName] = v; + } } }); }