Created
February 27, 2013 15:11
-
-
Save shaneriley/5048623 to your computer and use it in GitHub Desktop.
BinaryObject constructor
This file contains 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
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