IE上的startsWith和endWith方法

IE居然不支持这两个方法,好辣鸡!
依赖包:Javascript浏览器相关方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// 扩展IE浏览器的String原型方法
var Iflat = Iflat || {};
Iflat.Browser = {
extend: {
ieStringExtend: function () {
var browser = Iflat.Browser.info();
if (browser.name === 'ie') {
if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function (prefix) {
return this.slice(0, prefix.length) === prefix;
};
}
if (typeof String.prototype.endsWith != 'function') {
String.prototype.endsWith = function (suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
}
}
return browser;
}
}
}
分享到