Created
August 18, 2014 08:44
-
-
Save elrrrrrrr/dea04845eb2a6b70d315 to your computer and use it in GitHub Desktop.
js对象属性检测
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 好的写法 | |
if ('count' in object) | |
//判断DOM对象 IE8之前 DOM对象不从Object对象继承 需要判断 | |
//判断实例需要使用hasOwnProperty | |
if (object.hasOwnProperty("related")) { | |
//非dom对象 | |
} | |
if ("hasOwnProperty" in object && object.hasOwnProperty("related")) { | |
//兼容IE8 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment