A proposal to add String.prototype.format
Shanjian Li
shanjian at google.com
Wed Mar 9 11:50:43 PST 2011
It is ok for a give format specifier to apply to multiple type of object. In
your example, 'x' is applied to an array of numbers. But the language
interpreter should not do a hidden conversion to make it applicable. For
example, "{0:x}".("48") should throw an exception instead of trying to do a
hidden "toNumber()".
shanjian
On Wed, Mar 9, 2011 at 10:48 AM, P T Withington <ptw at pobox.com> wrote:
> 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.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110309/2f1ed7b1/attachment.html>
More information about the es-discuss
mailing list