I've been playing around with generating image filters using canvas, and I was attempting to improve speed by preallocating an entire matrix from the beginning.
This code was the first thing that I tried:
var N = 3
var matrix = new Array(N).map(function () { return new Array(N) })
// [ undefined x 3 ]
unfortunately, this doesn't do what I expect.
My expected result is given by this code:
N = 3;
matrix = [undefined,undefined,undefined].map(function () { return new Array(N) })
// [Array[3], Array[3], Array[3]]
Obviously, the preallocation can be done another way. This seems like it probably occurs due to some corner cutting done for performance in the implementation of javascript.
Anyone know why the first example doesn't do the same thing as the second?
Environments Checked:
OS: OSX Yosemite
Browsers: Chrome, Firefox Dev (same thing from both)