var a = Int32Array(10);
console.log(Array.isArray(a)); // prints false to the console (Firefox)
Is there a reason why a typed JavaScript array is not an array or is this a bug that needs to be reported?
有类型的JavaScript数组不是数组的原因还是需要报告的错误?
1 个解决方案
#1
No, typed arrays aren't arrays, it doesn't need reporting.
不,类型化数组不是数组,不需要报告。
They're a very distinct set of objects with different functions. In the specification, they're described as objects which
它们是一组具有不同功能的非常独特的对象。在说明书中,它们被描述为对象
present an array-like view of an underlying binary data buffer
呈现基础二进制数据缓冲区的类似数组的视图
A good reason not to confuse them : they don't even offer the functions you have on arrays, for example splice
.
不要混淆它们的一个很好的理由:它们甚至不提供阵列上的功能,例如拼接。
It also doesn't follow the spec of Array.isArray
as it's not an "Array object" as can be verified by setting the value at an out of range index using the bracket notation and checking the length
isn't changed.
它也不遵循Array.isArray的规范,因为它不是“数组对象”,因为可以通过使用括号表示法设置超出范围索引的值来验证,并且检查长度不会更改。
#1
No, typed arrays aren't arrays, it doesn't need reporting.
不,类型化数组不是数组,不需要报告。
They're a very distinct set of objects with different functions. In the specification, they're described as objects which
它们是一组具有不同功能的非常独特的对象。在说明书中,它们被描述为对象
present an array-like view of an underlying binary data buffer
呈现基础二进制数据缓冲区的类似数组的视图
A good reason not to confuse them : they don't even offer the functions you have on arrays, for example splice
.
不要混淆它们的一个很好的理由:它们甚至不提供阵列上的功能,例如拼接。
It also doesn't follow the spec of Array.isArray
as it's not an "Array object" as can be verified by setting the value at an out of range index using the bracket notation and checking the length
isn't changed.
它也不遵循Array.isArray的规范,因为它不是“数组对象”,因为可以通过使用括号表示法设置超出范围索引的值来验证,并且检查长度不会更改。