From 57d239c128ac0ad9be5390c6f1a23e9ab8a14dc7 Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Thu, 23 Jul 2020 13:19:12 -0700 Subject: [PATCH] Use + diff --git a/js/lib/ps-polyfill.js b/js/lib/ps-polyfill.js new file mode 100644 index 0000000000..50a6bc6720 --- /dev/null +++ b/js/lib/ps-polyfill.js @@ -0,0 +1,117 @@ +/** + * PS polyfill + * + * PS uses its own polyfills optimized for performance rather than + * standards-compliance (we simply don't use the features these + * polyfills don't provide). + * + * The biggest relevant difference is that we don't use + * `Object.defineProperty`, so you can't use `for...in` on Arrays, + * which everyone tells you not to do, anyway - you should be using + * `for...i` loops (or `for...of` with Babel's `assumeArray` setting). + * + * This polyfill is intended to be used in + diff --git a/src/battle-dex.ts b/src/battle-dex.ts index c63bff4ff6..393a7693f8 100644 --- a/src/battle-dex.ts +++ b/src/battle-dex.ts @@ -21,90 +21,6 @@ declare var require: any; declare var global: any; -if (!Array.prototype.indexOf) { - Array.prototype.indexOf = function indexOf(searchElement, fromIndex) { - for (let i = (fromIndex || 0); i < this.length; i++) { - if (this[i] === searchElement) return i; - } - return -1; - }; -} -if (!Array.prototype.includes) { - Array.prototype.includes = function includes(thing) { - return this.indexOf(thing) !== -1; - }; -} -if (!Array.isArray) { - Array.isArray = function isArray(thing): thing is any[] { - return Object.prototype.toString.call(thing) === '[object Array]'; - }; -} -if (!String.prototype.includes) { - String.prototype.includes = function includes(thing) { - return this.indexOf(thing) !== -1; - }; -} -if (!String.prototype.startsWith) { - String.prototype.startsWith = function startsWith(thing) { - return this.slice(0, thing.length) === thing; - }; -} -if (!String.prototype.endsWith) { - String.prototype.endsWith = function endsWith(thing) { - return this.slice(-thing.length) === thing; - }; -} -if (!String.prototype.trim) { - String.prototype.trim = function trim() { - return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); - }; -} -if (!Object.assign) { - Object.assign = function assign(thing: any, rest: any) { - for (let i = 1; i < arguments.length; i++) { - let source = arguments[i]; - for (let k in source) { - thing[k] = source[k]; - } - } - return thing; - }; -} -if (!Object.values) { - Object.values = function values(thing: any) { - let out: any[] = []; - for (let k in thing) { - out.push(thing[k]); - } - return out; - }; -} -if (!Object.keys) { - Object.keys = function keys(thing: any) { - let out: any[] = []; - for (let k in thing) { - out.push(k); - } - return out; - }; -} -if (!Object.entries) { - Object.entries = function entries(thing: any) { - let out: any[] = []; - for (let k in thing) { - out.push([k, thing[k]]); - } - return out; - }; -} -if (!Object.create) { - Object.create = function (proto: any) { - function F() {} - F.prototype = proto; - return new (F as any)(); - }; -} - if (typeof window === 'undefined') { // Node (global as any).window = global; diff --git a/testclient-beta.html b/testclient-beta.html index 7f94986482..4771cfa422 100644 --- a/testclient-beta.html +++ b/testclient-beta.html @@ -54,6 +54,7 @@