I am passing an empty array to a worker, which should populate the array and return it - I know there are other ways of doing this, but I'm more interested in why it isnt working, than getting it to work.
The main code:
var arr = new Array(4)
console.log(arr.length)//outputs 4
var worker = new Worker("whatever.js")
worker.postMessage(arr)
The worker code
self.onmessage = function(msg){
console.log(msg.data.length)//outputs 0
}
If I pass in a populated array, it works. If I even set a single entry of the array to a value, it works.
Why does the postMessage
function collapse non-zero-length, but empty arrays, is there a way of avoiding this? (apart from manually assigning a value)
.
I'm using Windows 7 and Chrome 51