Last active
August 29, 2015 14:17
-
-
Save frankiefu/ab7932dd26650ad0e3c9 to your computer and use it in GitHub Desktop.
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
<script> | |
Polymer({ | |
is: 'x-expression', | |
properties: { | |
operator: String, | |
left: String, | |
right: String, | |
value: { | |
notify: true, | |
computed: 'computeValue(operator, left, right)' | |
} | |
}, | |
binaryOperators: { | |
'+': function(l, r) { return l+r; }, | |
'-': function(l, r) { return l-r; }, | |
'*': function(l, r) { return l*r; }, | |
'/': function(l, r) { return l/r; }, | |
'%': function(l, r) { return l%r; }, | |
'<': function(l, r) { return l<r; }, | |
'>': function(l, r) { return l>r; }, | |
'<=': function(l, r) { return l<=r; }, | |
'>=': function(l, r) { return l>=r; }, | |
'==': function(l, r) { return l==r; }, | |
'!=': function(l, r) { return l!=r; }, | |
'===': function(l, r) { return l===r; }, | |
'!==': function(l, r) { return l!==r; }, | |
'&&': function(l, r) { return l&&r; }, | |
'||': function(l, r) { return l||r; } | |
}, | |
computeValue: function(operator, left, right) { | |
var fn = this.binaryOperators[operator]; | |
if (fn) { | |
return fn(left, right); | |
} | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment