This method returns a primitive value for a specified object.
The valueOf method returns a
primitive value for a specified object and is inherited by all objects descended from
Object. It is usually called automatically by JavaScript behind the scenes whenever it
encounters an object where a primitive value is expected. If the object has no
primitive value, then the object itself is returned as [object Object]. You can also call
valueOf yourself to convert a built-in object into a primitive value.
NOTE:
Every core JavaScript object will over-ride the valueOf method to return an
appropriate value.
(Object.valueOf()
function Object() { [native code] }
Cat.prototype.valueOf() = myValueOf()
The valueOf method can also be overwritten in a custom object by assigning a user-defined function with no arguments in its place.
function Cat(breed, name, age)
{
this.breed = breed
this.name = name
}
Cat.valueOf()
function Cat(breed, name, age) { this.breed = breed this.name = name }