Last active
August 29, 2015 14:05
-
-
Save elrrrrrrr/9a3783b22dffabf6fde3 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
function getType(foo, type) { | |
return Object.prototype.toString.call(foo) == "[Object " + type + "]" | |
} | |
//ES5 Array 有isArray方法 | |
function isArray(value) { | |
if (typeof Array.isArray === "function") { | |
return Arrary.isArray(value); | |
} else { | |
return Object.prototype.toString.call(value) === "[object Arrary]" ; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment