1function sprintf2(arg) { 2 if( arg.length < 2 ) { 3 return arg[0]; 4 } 5 var data = arg[ 0 ]; 6 for( var k=1; k<arg.length; ++k ) { 7 switch( typeof( arg[ k ] ) ) 8 { 9 case 'string': 10 data = data.replace( /%s/, arg[ k ] ); 11 break; 12 case 'number': 13 data = data.replace( /%d/, arg[ k ] ); 14 break; 15 case 'boolean': 16 data = data.replace( /%b/, arg[ k ] ? 'true' : 'false' ); 17 break; 18 default: 19 /// function | object | undefined 20 break; 21 } 22 } 23 return( data ); 24} 25if( !String.sprintf2 ) { 26 String.sprintf2 = sprintf2; 27}