| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,14 +14,6 @@ import mbglmap, { CRS, proj4, revertCRS } from '../../tool/mock_mapboxgl_map'; | |||
| 14 | 14 | import '../../resources/WebMapV3.js'; | |
| 15 | 15 | import '../../resources/WebMapV5.js'; | |
| 16 | 16 | var server = 'http://localhost:8190/iportal/'; | |
| 17 | - if (!Array.prototype.at) { | ||
| 18 | - Array.prototype.at = function(n) { | ||
| 19 | - n = Math.trunc(n) || 0; | ||
| 20 | - if (n < 0) n += this.length; | ||
| 21 | - if (n < 0 || n >= this.length) return undefined; | ||
| 22 | - return this[n]; | ||
| 23 | - }; | ||
| 24 | - } | ||
| 25 | 17 | describe('mapboxgl-webmap3.0', () => { | |
| 26 | 18 | var originalTimeout, testDiv; | |
| 27 | 19 | var id = 617580084; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,14 +13,7 @@ import * as mockL7 from '../../tool/mock_l7'; | |||
| 13 | 13 | import mbglmap, { CRS, proj4 } from '../../tool/mock_maplibregl_map'; | |
| 14 | 14 | import '../../resources/WebMapV3.js'; | |
| 15 | 15 | import '../../resources/WebMapV5.js'; | |
| 16 | - if (!Array.prototype.at) { | ||
| 17 | - Array.prototype.at = function(n) { | ||
| 18 | - n = Math.trunc(n) || 0; | ||
| 19 | - if (n < 0) n += this.length; | ||
| 20 | - if (n < 0 || n >= this.length) return undefined; | ||
| 21 | - return this[n]; | ||
| 22 | - }; | ||
| 23 | - } | ||
| 16 | + | ||
| 24 | 17 | describe('maplibregl-webmap3.0', () => { | |
| 25 | 18 | var originalTimeout, testDiv; | |
| 26 | 19 | var server = 'http://localhost:8190/iportal/'; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,36 @@ | |||
| 1 | + if (!Array.prototype.at) { | ||
| 2 | + Object.defineProperty(Array.prototype, 'at', { | ||
| 3 | + value: function at(index) { | ||
| 4 | + // 1. 让 O 成为 ToObject(this) | ||
| 5 | + if (this == null) { | ||
| 6 | + throw new TypeError('Cannot convert undefined or null to object'); | ||
| 7 | + } | ||
| 8 | + var O = Object(this); | ||
| 9 | + | ||
| 10 | + // 2. 让 len 成为 ToLength(O.length) | ||
| 11 | + var len = O.length >>> 0; | ||
| 12 | + | ||
| 13 | + // 3. 让 relativeIndex 成为 ToInteger(index) | ||
| 14 | + var relativeIndex = Math.trunc(index) || 0; | ||
| 15 | + | ||
| 16 | + // 如果参数是 NaN,Math.trunc(NaN) 是 NaN,NaN || 0 会将其变成 0 | ||
| 17 | + // 这符合标准(规范中 ToIntegerOrInfinity(undefined) 结果为 0) | ||
| 18 | + | ||
| 19 | + // 4. 计算实际索引 | ||
| 20 | + var k = relativeIndex >= 0 ? relativeIndex : len + relativeIndex; | ||
| 21 | + | ||
| 22 | + // 5. 边界检查:如果超出范围,返回 undefined | ||
| 23 | + if (k < 0 || k >= len) { | ||
| 24 | + return undefined; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + // 6. 返回对应的属性值 | ||
| 28 | + return O[k]; | ||
| 29 | + }, | ||
| 30 | + writable: true, | ||
| 31 | + configurable: true | ||
| 32 | + }); | ||
| 33 | + } | ||
| 1 | 34 | class Event { | |
| 2 | 35 | constructor() { | |
| 3 | 36 | this.stacks = {}; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments