Your function must take no arguments. With the preceding code in place, any time an object of type myNumberType is used in a context where it is to be represented as a primitive value, JavaScript automatically calls the function defined in the preceding code. Objects in string contexts convert via the toString method, which is different from String objects converting to string primitives using valueOf . But many objects do not convert to number, boolean, or function. See also parseInt , Object.toString watch Watches for a property to be assigned a value and runs a function when that occurs.
Parameters prop The name of a property of the object.
A function to call. If you delete a property for which a watchpoint has been set, that watchpoint does not disappear. If you later recreate the property, the watchpoint is still in effect. To remove a watchpoint, use the unwatch method. By default, the watch method is inherited by every object descended from Object .