From e91ce6387a21c8ae9838ce5a384c04df82ded013 Mon Sep 17 00:00:00 2001 From: yutent Date: Sun, 29 Sep 2024 15:05:05 +0800 Subject: [PATCH] fixed define --- package.json | 2 +- src/lib/array.js | 6 ++++-- src/lib/number.js | 3 ++- src/lib/promise.js | 6 +++++- src/lib/set.js | 3 ++- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 6ca5fa1..61cbff3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "es.shim", - "version": "2.4.2", + "version": "2.4.3", "description": "实现部分新API, 以及一些常用的扩展方法", "keyworks": [ "es5", diff --git a/src/lib/array.js b/src/lib/array.js index 17f3531..141e051 100644 --- a/src/lib/array.js +++ b/src/lib/array.js @@ -17,13 +17,15 @@ Object.defineProperty(Array.prototype, 'flat', { } return arr - } + }, + writable: true }) Object.defineProperty(Array.prototype, 'flatMap', { value(fn) { return this.map(fn).flat() - } + }, + writable: true }) if (!Array.prototype.at) { diff --git a/src/lib/number.js b/src/lib/number.js index 505e0eb..ab7a873 100644 --- a/src/lib/number.js +++ b/src/lib/number.js @@ -10,7 +10,8 @@ const NATIVE_TO_FIXED = Number.prototype.toFixed Object.defineProperty(Number.prototype, 'toFixed', { value(n) { return NATIVE_TO_FIXED.call(this + Number.EPSILON, n) - } + }, + writable: true }) // 简单的数字处理 diff --git a/src/lib/promise.js b/src/lib/promise.js index abbd882..03fde86 100644 --- a/src/lib/promise.js +++ b/src/lib/promise.js @@ -4,7 +4,7 @@ */ if (!Promise.defer) { - Promise.defer = function() { + Promise.defer = function () { let obj = {} obj.promise = new Promise((resolve, reject) => { obj.resolve = resolve @@ -13,3 +13,7 @@ if (!Promise.defer) { return obj } } + +if (!Promise.withResolvers) { + Promise.withResolvers = Promise.defer +} diff --git a/src/lib/set.js b/src/lib/set.js index 1fc26ce..a530868 100644 --- a/src/lib/set.js +++ b/src/lib/set.js @@ -104,5 +104,6 @@ if (!Set.prototype.union) { Object.defineProperty(Set.prototype, 'equals', { value(other) { return this.size === other.size && this.isSubsetOf(other) - } + }, + writable: true })