String.prototype.parseInt = function () {
if (typeof this === "number") {
return this;
} else if (typeof this === "string") {
let newStr = this.replace(/\s*/, '');
if (!newStr.length) {
return NaN;
} else if (!Number.isFinite(newStr[0] * 1)) {
return NaN;
} else if (newStr[0] === 0) {
return 0;
} else {
let arr = [];
for (let list of newStr) {
if (list !== '' && Number.isFinite(list * 1)) {
arr.push(list);
} else {
break;
}
}
if (arr.length) {
return arr.join("");
} else {
return NaN;
}
}
} else {
return NaN;
}}