TIP: Using Object.prototype.toString.apply(...);
You can use Object.prototype.toString.apply(<any JavaScript
object>); displays the value returned by primordial toString()
function even if the object's constructor function overrides the
toString() function.
For example (Array overrides the toString() function) :
alert([1,2,3].toString()); => '1,2,3'
alert(Object.prototype.toString.apply([1,2,3])); => '[object Array]' // better info than the next line
alert(typeof [1,2,3]); => 'object' // does not tell it is an Array
TIP: You can evaluate expressions like the above in the Firefox's Tools:Error Console's Evaluate text field.
Posted by sandipchitale
( Mar 31 2008, 11:07:56 PM PDT ) Permalink
Trackback URL: http://blogs.sun.com/scblog/entry/tip_using_object_prototype_tostring