sandip chitale's blog    Sandip Chitale's blog (scblog)
NOTE: I have moved many of my modules to NetBeans Plugin Portal . Please check there for latest versions of modules described on this blog.
20080331 Monday March 31, 2008

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 Comments [0]


Trackback URL: http://blogs.sun.com/scblog/entry/tip_using_object_prototype_tostring
Comments:

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed








« November 2009
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
     
       
Today

Get NetBeans 5.5

Locations of visitors to this page

Today's Page Hits: 357


XML
All
/Creator
/General
/Hobby
/Java
/JavaScript
/Mozilla
/NetBeans
/Ubuntu
/VisualWeb
/VisualWebPack
/Web 2.0

XML
All
/Creator
/General
/Hobby
/Java
/JavaScript
/Mozilla
/NetBeans
/Ubuntu
/VisualWeb
/VisualWebPack
/Web 2.0

scblog
scblog