- 主题:<javascript: the good part>判定是否数组类型求教
第六章, confusion部分
JavaScript does not have a good mechanism for distinguishing between arrays
and objects. We can work around that deficiency by defining our own is_array
function:
var is_array = function (value) {
return value &&
typeof value === 'object' &&
value.constructor === Array;
};
Unfortunately, it fails to identify arrays that were constructed in a
different window or frame.
最后一句话真心不懂,请教意思?
--
FROM 122.235.241.*
英文意思明白,实际意思不懂。
跨frame传过来,这个frame本身不也是js实现的。既然是js实现,是因为版本不同,以前的array不是构造函数实现的?
c/c++背景转过来学js,有不明白的地方,还望指点一二。
【 在 dhcn 的大作中提到: 】
: 那个方法对跨frame或者window传过来
--
FROM 218.108.104.*
谢谢,解释的很好。
【 在 radarxc1 (radarxc) 的大作中提到: 】
: value.constructor === Array 这句比较的是value.constructor是不是Array函
: 数,这里的Array是指当前域内的 Array函数。而对于跨域传过来的数组,
: value.constructor是原域内的Array函数,而不是现域的Array函数,所以会返回
: ...................
--
FROM 125.119.254.*