String.prototype.padString = function( len, pad, onRight )
{
var string = this,
pad = pad || "0",
onRight = onRight || false;
while( string.length < len )
//work out which end of the string the padding should be applied
onRight ?
string = string += pad :
string = pad + string ;
return string;
}
console.log( typeof "2".padString( 2 ) );
console.log( typeof "23".padString( 2 ) );