Skip to content

Instantly share code, notes, and snippets.

@petermichaux
Last active December 10, 2015 12:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save petermichaux/4431905 to your computer and use it in GitHub Desktop.
Save petermichaux/4431905 to your computer and use it in GitHub Desktop.
An object as a function of it's messages.
var adam = (function() {
var firstname = "Adam";
var lastname = "of Eden";
return function(message) {
switch (message) {
case "getName":
return firstname + " " + lastname;
default:
throw "unknown message " + message;
}
};
}());
adam("getName"); // "Adam of Eden"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment