检测数组和对象&扩展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");

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM