How to get the object type in javascript:
2011-05-05 10:23
781 查看
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
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
相关文章推荐
- How to get the object type in javascript:
- [SharePoint]javascript client object model 获取lookup 类型的field的值,包括user类型(单人或者多人)的值。how to get the multiple user type/lookup type field value by Javascript client object model
- How do I get the name of an object's type in JavaScript
- How to access the properties of an object in Javascript
- How can I get an object's absolute position on the page in Javascript?
- How to get a type in C++ when its template argument is the argument
- [eZ publish] When a ezxml embed an video, how to get the ezxml object in the video embed template?
- flex/in the datagrid,how to get the new value of cell in the datagrid after edit
- How to get IOleSite interface of the WebBrowser in an ActiveX control
- How to get and set the system socket buffer in AIX?
- How to Compare two layer’s object: Get AOT objects both modified in USR & SL1 layer
- How to select the data type in SQLserver database such as varchar, nvarchar
- How to get the available RAM and the cpu usage in percents?
- 在使用apt-get安装报错:To continue type in the phrase 'Yes, do as I say!' ?] 解决方法
- How to get the text from any standard object
- Silktest2011:How to get Browser type in openagent model?
- uiview 某点返回 色值 How to get the color of a pixel in an UIView?
- How to get the query string by javascript?
- How to Get the Length of File in C
- How to get the dmesg output in initramfs (debian)