How to get the object type in javascript:

var obj = {}; // any object

1. typeof:

typeof obj; // object

2. instanceof:

obj instanceof Object; // true

3. Object.prototype.toString:

Object.prototype.toString.call(obj); // [object Object]

4. constructor:

obj.constructor // Object

5. Duck:

typeof obj === "object" && "hasOwnProperty" in obj && "toString" in obj; // true

 

Reference Material: http://www.iteye.com/topic/318821

 

posted @ 2011-05-05 10:23  我是小菜鸟  阅读(138)  评论(0)    收藏  举报