Nov 13, 2010

object toString

The memeber toString of different object is redefined in their prototype, for example, Object.prototype.toString is different from Array.prototype.toString, to apply a Object.prototype.toString to an array object, we can write the following code

var toString = Object.prototype.toString;
alert([1, 2])); //[object Array]
alert([1, 2].toString()); //1,2

This will return the type of the object, "[object Array]"