提交 fd33936f authored 作者: vipcxj's avatar vipcxj

fix: trimXXX的polyfill

上级 d9fe7883
/* eslint-disable no-extend-native */
import '@babel/polyfill';
String.prototype.trimStart = String.prototype.trimStart ? String.prototype.trimStart : function trimStart() {
if (String.prototype.trimLeft) {
return this.trimLeft();
} else if (String.prototype.trim) {
String.prototype.trimLeft = String.prototype.trimLeft ? String.prototype.trimLeft : function trimLeft() {
const trimmed = this.trim();
const indexOfWord = this.indexOf(trimmed);
return this.slice(indexOfWord, this.length);
}
};
String.prototype.trimLeft = String.prototype.trimLeft ? String.prototype.trimLeft : String.prototype.trimStart;
String.prototype.trimStart = String.prototype.trimStart ? String.prototype.trimStart : String.prototype.trimLeft;
String.prototype.trimEnd = String.prototype.trimEnd ? String.prototype.trimEnd : function trimEnd() {
if (String.prototype.trimRight) {
return this.trimRight();
} else if (String.prototype.trim) {
String.prototype.trimRight = String.prototype.trimRight ? String.prototype.trimRight : function trimRight() {
const trimmed = this.trim();
const indexOfWord = this.indexOf(trimmed);
return this.slice(0, indexOfWord + trimmed.length);
}
};
String.prototype.trimRight = String.prototype.trimRight ? String.prototype.trimRight : String.prototype.trimEnd;
String.prototype.trimEnd = String.prototype.trimEnd ? String.prototype.trimEnd : String.prototype.trimRight;
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论