spy

(Note: if you aren’t using jasmine and jasmine-jquery to test your javascript go take care of that) Suppose we’re working on a sliding tile game, and we want to log the moves a player has made. We could create a Logger object to collect the moves, and use a callback in the Game method to update the logger. One of the simplest ways to implement a callback is with standalone function: Game.after_move = function() { for (var i = 0; i < this.
2012-12-17
3 min read