Skip to content

Commit

Permalink
fix(board): enable Board to be "sub-classed"
Browse files Browse the repository at this point in the history
Previously, the Board prototype was frozen. This caused problems for overriding methods in tictactoe.io,
and needed to be addressed. Problem solved.
  • Loading branch information
caitp committed Mar 12, 2014
1 parent 5c429d1 commit 6aca44b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 20 additions & 0 deletions test/board.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,24 @@ describe('Board', function() {
expect(callback).toHaveBeenCalledWith(jasmine.any(Object), 'Y', 0, 0);
});
});


it('should support subclasses overriding methods', function() {
var callback = jasmine.createSpy("move");
function SubBoard() {
Board.call(this);
}
SubBoard.prototype = Object.create(Board.prototype);
SubBoard.prototype.move = function() {
callback("SubBoard#move()");
}
var board = new SubBoard();
expect(board instanceof Board).toBe(true);
expect(board instanceof SubBoard).toBe(true);
expect(function() {
board.move();
}).not.toThrow();
expect(callback.callCount).toBe(1);
expect(callback).toHaveBeenCalledWith("SubBoard#move()");
});
});
1 change: 0 additions & 1 deletion tictactoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ function main() {
}
};
hidden(Board.prototype._emit);
freeze(Board.prototype);

function Move(player, x, y) {
this.player = player;
Expand Down

0 comments on commit 6aca44b

Please sign in to comment.