js string format All In One
js string format All In One
/*
String.prototype.format = function() {
var s = this;
for (var i = 0, j = arguments.length; i < j; i++)
s = s.replace("{" + (i) + "}", arguments[i]);
return (s);
}
*/
String.prototype.format = function() {
let str = this;
console.log('str =', str);
console.log('arguments =', arguments);
for (let i = 0; i < arguments.length; i++) {
str = str.replace("{" + i + "}", arguments[i]);
}
return str;
}
"{0}={1};expires={2};path={3}".format('name', 'value', 365, '/path');
// 'name=value;expires=365;path=/path'
refs
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/16456428.html
未经授权禁止转载,违者必究!