String.prototype.startsWith = function (str) {
if (str == null || str == "" || this.length == 0 || str.length > this.length) {
return false;
}
if (this.substring(0, s.length) == str) {
return true;
} else {
return false;
}
return true;
}### 问题描述
问题出现的环境背景及自己尝试过哪些方法
我直接放在script 标签中不行
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
可以放在main.js中。
不过看你的代码,ES6字符串扩展了这个函数,不需要自己来写的。
另外直接扩展原有的JS类型并不是一个推荐的方法。