这是我的代码:
var PLAYER_INIT_ROW = 6;
var PLAYER_INIT_COL = 3;
var Player = function(){
this.sprite = 'images/char-boy.png';
var row = PLAYER_INIT_ROW;
var col = PLAYER_INIT_COL;
log("row:"+row);
log("this.row:"+this.row);
log("this:"+this);
var coord = getCoord(row,col);
var x = coord.x;
var y = coord.y;
};
var player = new Player();
和日志:
row: 6 this.row: undefined this: [object Object]
和chrome调试器:
Local
col:3
coord:undefined
row:6
this:Player
sprite:"images/char-boy.png"
__proto__:Object
x:undefined
y:undefined
所以,'this'存在但是this.row未定义。我猜当构建完成时,this.row将被定义,不是吗?