I'm attempting to allow user defined logic criteria. Since the user definitions are basically strings, I'm trying to make the code efficient by avoiding string comparison. For example, a simple test like a == 10
would be represented by an array
var userDef = ['a', '==', 10]
To make the logic evaluation efficient, I'd like to create an object like the ffg:
var binaryOperator = {'==': 0, '>': 1, '<': 2}
.. so when I mine the array, I could do e.g.
if(binaryOperator[userdef[1]] == 0)
{
return (obj[userDef[0]] == userDef[2])
}
... where of course obj.a = something. The above code, on the face of it, avoids string comparison.
But does it really? Is the reference binaryOperator[userdef[1]]
really fast or does it also involve string comparison somewhere?
In other words is there a performance difference between thisObj.a
and thisObj['a']
?