标签:style blog color java io for cti ar
function(){ ‘use strict‘; if(String.prototype.format) return; String.prototype.format = function(args){ var _dict = typeof(args) == ‘object‘ ? args : arguments; return this.replace(/{([^{}]+)}/g,function(s,n){ return _dict[n]===undefined?s:_dict[n]; }); }; })();
useage:
var str = ‘{name} is {age} years old.‘; str.format({name:‘Tom‘,age:25});//”Tom is 25 years old.”
str = ‘{0} is {1} years old.‘; str.format(‘Jerry‘,15);//”Jerry is 15 years old.” str.format([‘Bill‘,10]);//"Bill is 10 years old."
javascript 之string.format,布布扣,bubuko.com
标签:style blog color java io for cti ar
原文地址:http://www.cnblogs.com/fly-could/p/3886033.html