0
我有一個奇怪的行爲,在JavaScript中有一個簡單的函數。我用矩陣書寫,但是當我再次閱讀時,我看不到變化。有人能解釋我爲什麼嗎? 下面是代碼:Javascript variable not written
this.map = [
'## ### ##',
'# # #',
'# # . # #',
'# ## # #',
'## # #',
'#*# ## ##',
' ## ',
'#########'
];
this.check_collision = function (x, y) {
var l = Math.floor (y/this.tile_size);
var c = Math.floor (x/this.tile_size);
if (this.map[ l ] != undefined) {
if (this.map[ l ][ c ] != undefined) {
if (this.map[ l ][ c ] == '#') {
return true;
}
else if (this.map[ l ][ c ] == '.' || this.map[ l ][ c ] == '*') {
this.map[ l ][ c ] = ' ';
console.debug ("'" + this.map[ l ][ c ] + "'");
}
}
}
return false;
};
的console.debug()打印 ''或'*',但我寫了字符''上面的行
測試'alert'而不是'console.debug'。你仍然得到相同的結果? –
是的。相同的結果 –
[示例代碼](http://sscce.org/)不完整。什麼實際存儲在'this.map [l]'中?如果它是一個字符串,字符串是不可變的。 – outis