I'm stuck in some part of my code. I created something like model class BoardEx and I want to create Iterator for it, here's some example:
Game.BoardEx = function(params){
...
this.board = Array(cols, rows);
...
}
where Game is the "parent" object of all children "classes". Then I declared Iterator:
Game.BoardEx.prototype.Iterator = function(){
var pos = {x: 0, y: -1};
this.next = function(){
...
return this.board[pos.x][pos.y];
};
Later usage is:
var board = new Game.BoardEx();
var iter = new board.Iterator();
It seems that I can't call this.board in this scope. Should I use bind or other method or just can't I call this at all?
new Iteratorand copying the board over (or a reference to it). Remember,this.boardbelongs to the created Iterator now and not the BoardEx object. Also, you want a method like.iterateon the BoardEx instance that doesreturn new Iterator(this)with the board passed so you can have access to it.var board = new Game.BoardEx(); var iter = new board.Iterator();