🐛compatible with vConsole who will wrap global variables with proxy (#2630)
This commit is contained in:
parent
afb92ed64d
commit
7328396c30
|
|
@ -40,12 +40,13 @@ export function getTargetValue(target: any, value: any): any {
|
||||||
|
|
||||||
const boundValue = Function.prototype.bind.call(value, target);
|
const boundValue = Function.prototype.bind.call(value, target);
|
||||||
|
|
||||||
// some callable function has custom fields, we need to copy the enumerable props to boundValue. such as moment function.
|
// some callable function has custom fields, we need to copy the own props to boundValue. such as moment function.
|
||||||
// use for..in rather than Object.keys.forEach for performance reason
|
Object.getOwnPropertyNames(value).forEach((key) => {
|
||||||
// eslint-disable-next-line guard-for-in,no-restricted-syntax
|
// boundValue might be a proxy, we need to check the key whether exist in it
|
||||||
for (const key in value) {
|
if (!boundValue.hasOwnProperty(key)) {
|
||||||
boundValue[key] = value[key];
|
Object.defineProperty(boundValue, key, Object.getOwnPropertyDescriptor(value, key)!);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// copy prototype if bound function not have but target one have
|
// copy prototype if bound function not have but target one have
|
||||||
// as prototype is non-enumerable mostly, we need to copy it from target function manually
|
// as prototype is non-enumerable mostly, we need to copy it from target function manually
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user