【发布时间】:2011-03-14 00:05:42
【问题描述】:
为了使我的一个函数的语法更好,我需要能够判断特定参数是数组还是“哈希”(我知道它们只是对象)。
Typeof 不起作用,因为它们都返回相同的东西
typeof {foo:"bar"} // Object
typeof ["foo","bar"] // Object
那么我该如何区分这两者呢?
我知道这可行,但我希望有更好的方法
({foo:"bar"}).constructor // Object()
(["foo","bar"]).constructor // [ undefined ]
编辑 啊,好像firebug中的[ undefined ]和Array是一样的。有点奇怪。
【问题讨论】:
标签: javascript