: -1 , getRandomMatrix. , , .
, , .
var cols = 9;
var rows = 9;
var matrix_empty = [];
function getRandomMatrix(matrix) {
matrix[0][1] = 39;
matrix[1][1] = 9;
matrix[2][2] = 9;
return matrix;
}
for (var x = 0; x < cols; x++) {
matrix_empty[x] = [];
for (var y = 0; y < rows; y++) {
matrix_empty[x][y] = -1;
}
}
console.clear();
console.log(matrix_empty);
setTimeout(function() {
matrix_test = getRandomMatrix(matrix_empty);
console.log(matrix_empty);
}, 10000);
Let's start with a delay of 10 seconds, so that you have time to open the array in the debugger and make sure that the values are really -1.
However, if you wait until the setTimeOut function starts in 10 seconds (or makes the timeout much shorter) without opening the array, after the second array is registered in the console, you can now open both arrays and make sure that yes , they were both changed. Another way to take a look at the introduction is to follow the vs pass by value link.
http://jsfiddle.net/vDgJ3/
source
share