You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 30, 2019. It is now read-only.
I found this issue a couple of days ago but thought it must be a non-issue, but since #70 it has appeared more often.
The JavaArray class extends Array but uses a different constructor signature. Because of this difference, native Array functions cannot work on JavaArrays (especially functions that return new instances of an array such as map).
Internally the native Array.Map function may initialise an Array with new Array(arrayLength) and then populate the indexes. As JavaArray assumes the first parameter will be an array and not a number, it fails on the forEach call.
For example
class NewArray extends Array { constructor(...elements) { super(...elements); console.log('i was called with:', ...elements); } }
const test1 = new NewArray()
// logs: I was called with:
test1.map(() => 1)
// logs: I was called with: 0
const test2 = new NewArray("a", "b", "c")
// logs: I was called with: "a", "b", "c"
test2.map(() => 1)
// logs: I was called with: 3
An alternative way to resolve this issue would be to re-implement the native functions in the JavaArray class
The text was updated successfully, but these errors were encountered:
I found this issue a couple of days ago but thought it must be a non-issue, but since #70 it has appeared more often.
The JavaArray class extends Array but uses a different constructor signature. Because of this difference, native Array functions cannot work on JavaArrays (especially functions that return new instances of an array such as
map
).Internally the native Array.Map function may initialise an Array with
new Array(arrayLength)
and then populate the indexes. As JavaArray assumes the first parameter will be an array and not a number, it fails on theforEach
call.For example
An alternative way to resolve this issue would be to re-implement the native functions in the JavaArray class
The text was updated successfully, but these errors were encountered: