- lprim ToPrimitive (lval).
- rprim - ToPrimitive (rval).
ToPrimitive :
O [[DefaultValue]] , , Number, O (. 15.9.6), , .
, , Number:
When the [[DefaultValue]] internal method of O is called with hint Number, the following steps are taken:
1. Let valueOf be the result of calling the [[Get]] internal method of object O with argument "valueOf".
2. If IsCallable(valueOf) is true then, a. Let val be the result of calling the [[Call]] internal method of valueOf, with O as the this value and an empty argument list. b. If val is a primitive value, return val.
3. Let toString be the result of calling the [[Get]] internal method of object O with argument "toString".
4. If IsCallable(toString) is true then, a. Let str be the result of calling the [[Call]] internal method of toString, with O as the this value and an empty argument list. b. If str is a primitive value, return str.
5. Throw a TypeError exception.
[].valueOf() , [].toString(), "".
, , .toString [object Object], .toString .join(",")
{} + []
{} , . , :
{}
+[]; //Same as +[] ( Number([]) ) which is 0
{} + [],
({}) + [] ({} + [])
:
{} ! []
({}) ! []