I am currently writing a compare function for js's Array.prototype.sort(). The question now is: I have an object instance a
with both variables and functions I want to sort after. I learned yesterday that I can access functions (I have the method name of) like this a['fct']()
.
So what I would like to do is something like
a['fct'] (typeof a['fct'] === 'function' ? () : nothing)
So I basically want to execute it if it's a function and just use it as a variable if it's a variable. I would like to omit a whole block with the same sorting logic, so I would like to keep it with the ternary operator style. Is this possible?