Created
November 6, 2008 11:41
-
-
Save javascripter/22565 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
var operator = { | |
add: function (a, b) { | |
return a + b; | |
}, | |
contains: function (a, b) { | |
return a in b; | |
}, | |
division: function (a, b) { | |
return a / b; | |
}, | |
and: function (a, b) { | |
return a & b; | |
}, | |
xor: function (a, b) { | |
return a ^ b; | |
}, | |
invert: function (a) { | |
return ~ a; | |
}, | |
or: function (a, b) { | |
return a | b; | |
}, | |
setitem: function (o, k, v) { | |
return o[k] = v; | |
}, | |
delitem: function (o, k) { | |
return delete o[k]; | |
}, | |
getitem: function (o, k) { | |
return o[k]; | |
}, | |
lshift: function (a, b) { | |
return a << b; | |
}, | |
mod: function (a, b) { | |
return a % b; | |
}, | |
mul: function (a, b) { | |
return a * b; | |
}, | |
neg: function (a) { | |
return - a; | |
}, | |
not: function (a) { | |
return ! a; | |
}, | |
rshift: function (a, b) { | |
return a >> b; | |
}, | |
sub: function (a, b) { | |
return a - b; | |
}, | |
lt: function (a, b) { | |
return a < b; | |
}, | |
le: function (a, b) { | |
return a <= b; | |
}, | |
eq: function (a, b) { | |
return a == b; | |
}, | |
equal: function (a, b) { | |
return a === b; | |
}, | |
nequal: function (a, b) { | |
return a !== b; | |
}, | |
ne: function (a, b) { | |
return a != b; | |
}, | |
ge: function (a, b) { | |
return a >= b; | |
}, | |
gt: function (a, b) { | |
return a > b; | |
}, | |
land: function (a, b) { | |
return a && b; | |
}, | |
lor: function (a, b) { | |
return a || b; | |
}, | |
ternary: function (a, b, c) { | |
return a ? b : c; | |
}, | |
typeof: function (a) { | |
return typeof a; | |
}, | |
instanceof: function (a, b) { | |
return a instanceof b; | |
}, | |
new: function (a) { | |
var args = Array.slice(arguments, 1); | |
return new Function( | |
'args', | |
'c', | |
'return new c(' + args.map(function (_, i) { | |
return 'args[' + i + ']'; | |
}).join(',') + ')')(args, a); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment