1 Star 0 Fork 4

witcit/mdjs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
polyfill.js 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
(function () {
//Copy from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim
polyfill('trim', function () {
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
});
//Copy from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
polyfill('startsWith', function (searchString, position) {
position = position || 0;
return this.substr(position, searchString.length) === searchString;
});
//Copy from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
polyfill('endsWith', function (searchString, position) {
var subjectString = this.toString();
if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
position = subjectString.length;
}
position -= searchString.length;
var lastIndex = subjectString.lastIndexOf(searchString, position);
return lastIndex !== -1 && lastIndex === position;
});
/**
* @param {string} name
* @param {Function} func
*/
function polyfill(name, func) {
if (!String.prototype[name])
String.prototype[name] = func;
}
})();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/witcit/mdjs.git
git@gitee.com:witcit/mdjs.git
witcit
mdjs
mdjs
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385