Skip to content

Commit

Permalink
fix: Object.defineProperty doesn't work in IE8
Browse files Browse the repository at this point in the history
  • Loading branch information
ambit-tsai committed Dec 24, 2020
1 parent ac37ff8 commit 8d7c9c1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,18 @@ if (isFunction(globalObject.AggregateError)) {


export let set: (obj: object, key: PropertyKey, val: unknown, readonly?: boolean) => void;
if (isFunction(Object.defineProperty)) {
try {
// In IE 8, `Object.defineProperty` is only effective on `Element` object,
// `document` and `window`. The program will throw an exception when
// `Object.defineProperty` works with others.
Object.defineProperty({}, '', {});

set = (obj, key, val, readonly = false) => {
Object.defineProperty(obj, key, {
configurable: !readonly,
value: val,
});
};
} else {
} catch (error) {
set = (obj, key, val) => obj[key] = val;
}


// const logError: Function = globalObject.console?.error || (() => {});

0 comments on commit 8d7c9c1

Please sign in to comment.