Skip to content

Instantly share code, notes, and snippets.

@Ivanca
Last active December 12, 2015 13:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ivanca/4781307 to your computer and use it in GitHub Desktop.
Save Ivanca/4781307 to your computer and use it in GitHub Desktop.
(function () {
var addMethod = function (obj, name, fn) {
obj[name] = function () {
var undef;
var result = fn.apply(obj, arguments);
if (result === undef) {
result = this;
}
return result;
};
};
var game = window.game = {};
var _game = {};
_game.active = true;
_game.playerName = "ekeisco";
addMethod(game, "print", function (msg) {
alert(msg);
});
addMethod(game, "lost", function (msg) {
_game.active = false;
this.print(msg || "You lose!");
});
addMethod(game, "getPlayerName", function (msg) {
return _game.playerName;
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment