Skip to content

Instantly share code, notes, and snippets.

@elrrrrrrr
Last active August 29, 2015 14:05
Show Gist options
  • Save elrrrrrrr/9a3783b22dffabf6fde3 to your computer and use it in GitHub Desktop.
Save elrrrrrrr/9a3783b22dffabf6fde3 to your computer and use it in GitHub Desktop.
判断JS引用对象类型
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