From 6bd0ca46a390c6df4e9bcc4aa3f345cbf541496a Mon Sep 17 00:00:00 2001 From: gzezFISHER Date: Wed, 29 Jul 2020 15:05:44 +0800 Subject: [PATCH] fix replaceall --- src/StringPrototype.js | 9 +++++++-- src/components/user/register.vue | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/StringPrototype.js b/src/StringPrototype.js index 851d4953..6e4b7bc1 100644 --- a/src/StringPrototype.js +++ b/src/StringPrototype.js @@ -2,9 +2,9 @@ if (String.prototype.replaceAll === undefined) { String.prototype.replaceAll = function (before, after) { let res = new String(), matched = 0; for (let i = 0; i < this.length; i += 1) { - if (this[i] == before[matched]) { + if (this[i] === before[matched]) { matched += 1; - if (matched == before.length) { + if (matched === before.length) { res += after; matched = 0; } @@ -13,6 +13,11 @@ if (String.prototype.replaceAll === undefined) { res += this[i]; } } + + for (let i = this.length - matched; i < this.length; i += 1) { + res += this[i]; + } + return res; }; } \ No newline at end of file diff --git a/src/components/user/register.vue b/src/components/user/register.vue index 2d735a00..7b880e9d 100644 --- a/src/components/user/register.vue +++ b/src/components/user/register.vue @@ -14,7 +14,7 @@ -
Email
+
Email