F
florian.loitsch
hi,
I'm having troubles understanding the meaning of the "valueOf" method,
as described in the ECMA-262 (3rd Edition) standard.
I quote (section 15.2.4.4, page 85):
===
"The _valueOf_ method returns its _this_ value. If the object is the
result of calling the Object constructor with a host object
(15.2.2.1), it is implementation-defined wether _valueOf_ returns its
_this_ value or another value such as the host object originally
passed to the constructor."
===
My initial reflex was to just return "this". Obviously this wasn't the
case...
I then suspected the method to return the (internal) [[Value]]-
property of the this object. This makes sense, as the 'toValue' of a
Date-object returns an integer (which is the [[Value]]-property as
defined in 15.9.3.2).
However: it is clearly stated, that an Object created by 'new
Object()' does not have any [[Value]]-property (section 15.2.2.1):
===
"The newly constructed object has no [[Value]] property".
===
Also, I was not able to find any [[Value]]-related information for
Array or Function objects.
It seems that all available implementations return the object itself
in such cases, but is there somewhere a more precise explanation?
mfg,
// florian loitsch
I'm having troubles understanding the meaning of the "valueOf" method,
as described in the ECMA-262 (3rd Edition) standard.
I quote (section 15.2.4.4, page 85):
===
"The _valueOf_ method returns its _this_ value. If the object is the
result of calling the Object constructor with a host object
(15.2.2.1), it is implementation-defined wether _valueOf_ returns its
_this_ value or another value such as the host object originally
passed to the constructor."
===
My initial reflex was to just return "this". Obviously this wasn't the
case...
I then suspected the method to return the (internal) [[Value]]-
property of the this object. This makes sense, as the 'toValue' of a
Date-object returns an integer (which is the [[Value]]-property as
defined in 15.9.3.2).
However: it is clearly stated, that an Object created by 'new
Object()' does not have any [[Value]]-property (section 15.2.2.1):
===
"The newly constructed object has no [[Value]] property".
===
Also, I was not able to find any [[Value]]-related information for
Array or Function objects.
It seems that all available implementations return the object itself
in such cases, but is there somewhere a more precise explanation?
mfg,
// florian loitsch