Jeff Walden (2014-08-26T16:27:24.000Z)
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
domenic at domenicdenicola.com (2014-09-08T23:25:29.070Z)
On 08/26/2014 09:14 AM, Brendan Eich wrote:

> 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.