/
githubmirror
/
taro
Обзор
Документация
Войти
/
githubmirror
/
taro
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/taro-runtime/src/polyfill/array.ts
54 строки
1 KB
ZakaryCode
feat(runtime): 更新运行时依赖文件
15 янв 2024, 10:02
15 янв 2024, 10:02
9a68b7b
Код
Авторство
О чём код?
import { isFunction } from '@tarojs/shared' export function handleArrayFindPolyfill () { if (!isFunction(Array.prototype.find)) { Object.defineProperty(Array.prototype, 'find', { value (predicate) { if (this == null) { throw new TypeError('"this" is null or not defined') } const o = Object(this) const len = o.length >>> 0 if (!isFunction(predicate)) { throw new TypeError('predicate must be a function') } const thisArg = arguments[1] let k = 0 while (k < len) { const kValue = o[k] if (predicate.call(thisArg, kValue, k, o)) { return kValue } k++ } return undefined } }) } } export function handleArrayIncludesPolyfill () { if (!isFunction(Array.prototype.includes)) { Object.defineProperty(Array.prototype, 'includes', { value (searchElement, fromIndex) { if (this == null) { throw new TypeError('"this" is null or not defined') } const o = Object(this) const len = o.length >>> 0 if (len === 0) { return false } const n = fromIndex | 0 let k = Math.max(n >= 0 ? n : len - Math.abs(n), 0) while (k < len) { if (o[k] === searchElement) { return true } k++ } return false } }) } }