473,395 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

valueOf method

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

Aug 6 '07 #1
2 1530
fl*************@gmail.com wrote:
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...
Of course it was not. The `this' value of a method is a reference to the
object that was used to call it:

| 10.1.7 This
|
| There is a *this* value associated with every active execution context.
| The *this* value depends on the caller and the type of code being executed
| and is determined when control enters the execution context. The *this*
| value associated with an execution context is immutable.

| 10.2 Entering An Execution Context
|
| [...]
| When control enters an execution context, the scope chain is created and
| initialised, variable instantiation is performed, and the *this* value is
| determined.
|
| The initialisation of the scope chain, variable instantiation, and the
| determination of the *this* value depend on the type of code being
| entered.

| 10.2.3 Function Code
|
| [...]
| - The caller provides the *this* value. If the *this* value provided by
| the caller is not an object (including the case where it is null), then
| the *this* value is the global object.
Also, I was not able to find any [[Value]]-related information for
Array or Function objects.
| 15.3.4 Properties of the Function Prototype Object
|
| [...]
| The Function prototype object does not have a valueOf property of its own;
| however, it inherits the valueOf property from the Object prototype
| Object.

| 15.4.4 Properties of the Array Prototype Object
|
| [...]
| NOTE The Array prototype object does not have a valueOf property of its
| own; however, it inherits the valueOf property from the Object prototype
| Object.

HTH

PointedEars
Aug 6 '07 #2
On Aug 6, 11:54 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
florian.loit...@gmail.com wrote:
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...

Of course it was not. The `this' value of a method is a reference to the
object that was used to call it:
Obviously I meant the 'this' keyword (which is the correct answer). I
was
just confused, as strings and numbers where not returning the this-
value.
I just forgot to verify if they had "overwritten" methods.
Stupid...
thanks
// florian
>
| 10.1.7 This
|
| There is a *this* value associated with every active execution context.
| The *this* value depends on the caller and the type of code being executed
| and is determined when control enters the execution context. The *this*
| value associated with an execution context is immutable.

| 10.2 Entering An Execution Context
|
| [...]
| When control enters an execution context, the scope chain is created and
| initialised, variable instantiation is performed, and the *this* value is
| determined.
|
| The initialisation of the scope chain, variable instantiation, and the
| determination of the *this* value depend on the type of code being
| entered.

| 10.2.3 Function Code
|
| [...]
| - The caller provides the *this* value. If the *this* value provided by
| the caller is not an object (including the case where it is null), then
| the *this* value is the global object.
Also, I was not able to find any [[Value]]-related information for
Array or Function objects.

| 15.3.4 Properties of the Function Prototype Object
|
| [...]
| The Function prototype object does not have a valueOf property of its own;
| however, it inherits the valueOf property from the Object prototype
| Object.

| 15.4.4 Properties of the Array Prototype Object
|
| [...]
| NOTE The Array prototype object does not have a valueOf property of its
| own; however, it inherits the valueOf property from the Object prototype
| Object.

HTH

PointedEars

Aug 7 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Dave Rahardja | last post by:
OK, so I've gotten into a philosophical disagreement with my colleague at work. He is a proponent of the Template Method pattern, i.e.: class foo { public: void bar() { do_bar(); } protected:...
5
by: Chris | last post by:
Hi I have a scenario where I've created another AppDomain to dynamically load a DLL(s) into. In this newly loaded DLL I want to call a static method on a class. The problem arise is that I have...
19
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
4
by: daniel.w.gelder | last post by:
I wrote a template class that takes a function prototype and lets you store and call a C-level function, like this: inline string SampleFunction(int, bool) {..} functor<string (int, bool)>...
7
by: greenflame | last post by:
I am trying to make a matrix object. I have given it some properites. I am trying to add a method. When I call the method by Test.showDims(...) I want to only enter one input, that is the method by...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
10
by: Mihai Osian | last post by:
Hi everyone, Given the code below, can anyone tell me: a) Is this normal behaviour ? b) If it is, what is the reason behind it ? I would expect the A::method(int) to be inherited by B. ...
3
by: Marco Bizzarri | last post by:
On Sat, Sep 13, 2008 at 4:11 PM, Fredrik Lundh <fredrik@pythonware.comwrote: "verbose mess". It is always frustrating when you do what you think is your best and you read that. Anyway: I'm...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.