Skip to content

Instantly share code, notes, and snippets.

@shaneriley
Created February 27, 2013 15:11
Show Gist options
  • Save shaneriley/5048623 to your computer and use it in GitHub Desktop.
Save shaneriley/5048623 to your computer and use it in GitHub Desktop.
BinaryObject constructor
BinaryObject = function(a, b) {
var o = {
0: a,
1: b,
val: function(bool) { return bool ? this[1] : this[0]; }
};
return o;
};
var bin = new BinaryObject("no", "yes");
console.log(bin.val(true)); // "yes"
var complete_message = BinaryObject("incomplete", "complete");
console.log(complete_message.val("")); // "incomplete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment