Last active
December 12, 2015 13:58
-
-
Save Ivanca/4781307 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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