- 为String对象添加formatByObject方法
String.prototype.formatByObject = function () {
if (arguments.length == 0) return this;
var obj = arguments[0];
var s = this;
for (var key in obj) {
s = s.replace(new RegExp("\\{\\{" + key + "\\}\\}", "g"), obj[key]);
}
return s;
}
- 使用方法
window.open((API.RECORD + ("?token={{token}}".formatByObject({
token: res.data[0].access_token
}))), '_blank');