Implicit coercion of Symbols

Axel Rauschmayer axel at rauschma.de
Sat Jan 3 11:06:03 PST 2015


> On 03 Jan 2015, at 19:52, Brendan Eich <brendan at mozilla.org> wrote:
> 
> None of the objects in the examples bz cited are Arrays -- what did you mean?

When I though of `+` being used inside square brackets, I only thought of strings, not of numbers (first example).

In the first example, `this` is at least array-like. Otherwise, `slice` wouldn’t work.

> Axel Rauschmayer wrote:
>> Arrays are a good point, this is where I’d think accidental coercions are most likely. The other use case is object-as-dictionary, which will slowly be replaced by `Object.create(null)` (no need to escape in ES6+) and `Map`.
>> 
>> I don’t feel strongly either way, I just feel that the added spec complexity is not ideal. Especially ToBoolean() not throwing an exception, while ToString() and ToNumber() do.
>> 
>>> On 03 Jan 2015, at 04:02, Boris Zbarsky <bzbarsky at mit.edu <mailto:bzbarsky at mit.edu>> wrote:
>>> 
>>> On 1/2/15 9:40 PM, Axel Rauschmayer wrote:
>>>> Can you give an example?
>>> 
>>> get: function( num ) {
>>> return num != null ?
>>> 
>>> // Return just the one element from the set
>>> ( num < 0 ? this[ num + this.length ] : this[ num ] ) :
>>> 
>>> // Return all the elements in a clean array
>>> slice.call( this );
>>> },
>>> 
>>> That's from jQuery 2.1.3.
>>> 
>>> And from the same place:
>>> 
>>> function cache( key, value ) {
>>> // Use (key + " ") to avoid collision with native prototype properties (see Issue #157)
>>> if ( keys.push( key + " " ) > Expr.cacheLength ) {
>>> // Only keep the most recent entries
>>> delete cache[ keys.shift() ];
>>> }
>>> return (cache[ key + " " ] = value);
>>> }

-- 
Dr. Axel Rauschmayer
axel at rauschma.de
rauschma.de



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150103/5acc6dab/attachment.html>


More information about the es-discuss mailing list