A proposal to add String.prototype.format

P T Withington ptw at pobox.com
Wed Mar 9 10:48:05 PST 2011


On 2011-03-09, at 13:20, Shanjian Li wrote:

>> It doesn't specify how to print objects, except for %s, which says that if
>> the argument is not
>> a string, convert it to string using .toString().
>> 
> 
> If the format specifier does not apply to the argument given, it should
> raise exceptions. Except string conversion, no other conversion will be
> done.

Disagree.  Since ECMAScript knows the type of the arguments, it does _not_ need the format specifier to tell it the type (as C does).  Apparent mismatches should be left open as extensions.  For example, the `x` formatter should simply specify that numeric values should be expressed in base 16, not that the value _must_ be a number.  That way, you could pass an Array of numbers to `x` and see the numbers in base 16.



More information about the es-discuss mailing list