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
路慢慢其休远羲,吾将上下而求所

浙公网安备 33010602011771号