On Sat, Jan 8, 2011 at 8:21 PM, Devin Samarin <[email protected]> wrote:
> // Let `str be the result of calling ToString passing the
> `this value as the argument.
> var str = ""+this;
Trivia: ""+obj is not the same thing as ToString(obj). They differ if
obj has a .valueOf method.
js> ""+({valueOf: function(){return 1;}})
"1"
js> String({valueOf: function(){return 1;}})
"[object Object]"
I find Note 1 in ES5 11.9.3 a bit misleading in this regard.
Also trivia: For what it's worth, you can use Array(+n+1).join(s) as a
rough approximation of s.repeat(n). It even has pretty reasonable
error behavior (throwing a RangeError for most nonsensical values of
n, though not all).
-j
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss