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.

Comments:

Post a Comment:
Comments are closed for this entry.
About

sandipchitale

Search

Archives
« April 2014
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