我已经制作了这个沙盒测试:
<html>
<head>
<title>whatever</title>
<script type="text/javascript">
function myLittleTest() {
var obj, arr, armap;
arr = [1, 2, 3, 5, 7, 11];
obj = {};
obj = arr;
alert (typeof arr);
alert (typeof obj);
// doesn't work in IE
armap = obj.map(function (x) { return x * x; });
alert (typeof armap);
}
myLittleTest();
</script>
</head>
<body>
</body>
</html>
我知道可以使用jQuery的$.map函数使这行代码工作,但是,在JavaScript数据类型方面我错过了什么?
typeof
得到object
,因为数组只是带有数字属性、一些额外方法和一个神奇的length
属性的对象。 - bdukes