检测数组和对象&扩展String.prototype.format 字符串拼接的功能
检测数组和对象的方法:
var a=new Array(); var b=new Object(); console.log(Object.prototype.toString.call(a)); console.log(Object.prototype.toString.call(b));
扩展String.prototype.format 字符串拼接的功能:
//扩展 string.format
String.prototype.format = function () {
var args = arguments;
var reg = /\{(\d+)\}/g;
return this.replace(reg, function (g0, g1) {
return args[+g1];
});
};
//用法:
var k="a{0}b{1}".format("qqq","www");

浙公网安备 33010602011771号