typeof extensibility, building on my Value Objects slides from Thursday's TC39 meeting

Brendan Eich brendan at mozilla.com
Sun Aug 4 20:54:30 PDT 2013

David Bruant wrote:
> Le 04/08/2013 00:10, Brandon Benvie a écrit :
>> On 8/3/2013 12:30 PM, David Bruant wrote:
>>> That said, I recently worked on a project and I reviewed a pull 
>>> request with "typeof x === 'object'" to ask to replace to 'Object(x) 
>>> === x'.
>> On a side note, I think your version of isObject is problematic 
>> because it requires allocating an object every time the function 
>> encounters a primitive.
> It's not required. That's the raw reading of the spec and that's 
> probably what the implementations do, but it's not required. When 
> reading "if(Object(x) === x)", the JS engine, at the time of calling 
> "Object(x)" knows that the outcome won't be used except for its 
> identity. It also knows that what matters isn't even the identity, but 
> whether the identity is equal to x. In essence, the allocation isn't 
> required per se.

Does any engine actually optimize away the wrapper?

>> I'd prefer avoiding the unnecessary allocation in a function that is 
>> likely to be called very often.
> It's a very short-lived object anyway and Generational Garbage 
> Collection is very efficient with them.



More information about the es-discuss mailing list