fixed define

master
yutent 2024-09-29 15:05:05 +08:00
parent 4e459de01c
commit e91ce6387a
5 changed files with 14 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "es.shim", "name": "es.shim",
"version": "2.4.2", "version": "2.4.3",
"description": "实现部分新API, 以及一些常用的扩展方法", "description": "实现部分新API, 以及一些常用的扩展方法",
"keyworks": [ "keyworks": [
"es5", "es5",

View File

@ -17,13 +17,15 @@ Object.defineProperty(Array.prototype, 'flat', {
} }
return arr return arr
} },
writable: true
}) })
Object.defineProperty(Array.prototype, 'flatMap', { Object.defineProperty(Array.prototype, 'flatMap', {
value(fn) { value(fn) {
return this.map(fn).flat() return this.map(fn).flat()
} },
writable: true
}) })
if (!Array.prototype.at) { if (!Array.prototype.at) {

View File

@ -10,7 +10,8 @@ const NATIVE_TO_FIXED = Number.prototype.toFixed
Object.defineProperty(Number.prototype, 'toFixed', { Object.defineProperty(Number.prototype, 'toFixed', {
value(n) { value(n) {
return NATIVE_TO_FIXED.call(this + Number.EPSILON, n) return NATIVE_TO_FIXED.call(this + Number.EPSILON, n)
} },
writable: true
}) })
// 简单的数字处理 // 简单的数字处理

View File

@ -4,7 +4,7 @@
*/ */
if (!Promise.defer) { if (!Promise.defer) {
Promise.defer = function() { Promise.defer = function () {
let obj = {} let obj = {}
obj.promise = new Promise((resolve, reject) => { obj.promise = new Promise((resolve, reject) => {
obj.resolve = resolve obj.resolve = resolve
@ -13,3 +13,7 @@ if (!Promise.defer) {
return obj return obj
} }
} }
if (!Promise.withResolvers) {
Promise.withResolvers = Promise.defer
}

View File

@ -104,5 +104,6 @@ if (!Set.prototype.union) {
Object.defineProperty(Set.prototype, 'equals', { Object.defineProperty(Set.prototype, 'equals', {
value(other) { value(other) {
return this.size === other.size && this.isSubsetOf(other) return this.size === other.size && this.isSubsetOf(other)
} },
writable: true
}) })