您的位置:首页 > 移动开发 > Objective-C

How to get the object type in javascript:

2011-05-05 10:23 621 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: