Created
May 28, 2011 20:13
-
-
Save olooney/997192 to your computer and use it in GitHub Desktop.
javascript operators wrapped in functions so you can refer to them by name
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
op = { | |
"!!": function(x) { return !!x; }, | |
"!": function(x) { return !x; }, | |
"&&": function(x, y) { return x && y; }, | |
"||": function(x, y) { return x || y; }, | |
"~": function(x) { return ~x; }, | |
"negative": function(x) { return -x; }, | |
"+": function(x, y) { return x + y; }, | |
"-": function(x, y) { return x - y; }, | |
"/": function(x, y) { return x / y; }, | |
"%": function(x, y) { return x % y; }, | |
"*": function(x, y) { return x * y; }, | |
"&": function(x, y) { return x & y; }, | |
"|": function(x, y) { return x | y; }, | |
"^": function(x, y) { return x ^ y; }, | |
"<<": function(x, y) { return x << y; }, | |
">>": function(x, y) { return x >> y; }, | |
">>>": function(x, y) { return x >>> y; }, | |
"==": function(x, y) { return x == y; }, | |
"!=": function(x, y) { return x != y; }, | |
"===": function(x, y) { return x === y; }, | |
"!==": function(x, y) { return x !== y; }, | |
">": function(x, y) { return x > y; }, | |
"<": function(x, y) { return x < y; }, | |
">=": function(x, y) { return x >= y; }, | |
"<=": function(x, y) { return x <= y; }, | |
"typeof": function(x) { return typeof x; }, | |
"in": function(x, y) { return x in y; }, | |
"instanceof": function(x, y) { return x instanceof y; } | |
}; | |
// english aliases? | |
op["truth"] = op['!!']; | |
op["not"] = op['!']; | |
op["and"] = op['&&']; | |
op["or"] = op['||']; | |
op["plus"] = op['+']; | |
op["minus"] = op['-']; | |
op["divided by"] = op['/']; | |
op["times"] = op['*']; | |
op["modulo"] = op['%']; | |
op["equals"] = op['===']; | |
op["does not equal"] = op['!==']; | |
op["greater than"] = op[">"]; | |
op["less than"] = op["<"]; | |
op["not greater than"] = op["<="]; | |
op["not less than"] = op[">="]; | |
op["contains"] = function(x, y) { return y in x; }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment