global.d.ts 347 B

12345678910111213
  1. interface String {
  2. format(...param);
  3. }
  4. String.prototype.format = function (...param) {
  5. //将arguments转化为数组(ES5中并非严格的数组)
  6. var args = Array.prototype.slice.call(arguments);
  7. var count = 0;
  8. //通过正则替换%s
  9. return this.replace(/%s/g, function (s, i) {
  10. return args[count++];
  11. });
  12. }