On 08/26/2014 09:14 AM, Brendan Eich wrote: > Claude Pache wrote: >> Personally, I use the following expression in order to coerce a variable to >> a string: >> >> var obj = this + '' >> >> and its in-place variant: >> >> x += '' >> >> I think it'll continue to work in ES6. > > Agreed, this is the correct-and-most-concise way to do it.
It's not the most correct way to do it. |a + ""| performs ToPrimitive(a, hint = None), whereas ToString(a) performed ToPrimitive(a, hint = String). The former consults valueOf, then toString, the latter the reverse. > using String(any) to invoke ToString is verbose and fragile, because String > could be rebound :-P. Generally polyfills are fine with that limitation, and only us language pedants need worry/care about String being rebound. All the array-method polyfills we've provided on MDN depend on non-rebinding of some builtin function or other. It's not that big a deal. Jeff _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

