In my object structure, both utils
and utils.not
have the same prototype with an exist
method. To keep it simple, here is a clearer version:
var negative = true;
if(negative){
//when negative===true, I want to run exist() through not object
tests.utils.not.exist();
} else {
tests.utils.exist();
}
Is there a way to dynamically exclude not
from the chain without using an IF
statement? For example, if I wanted to change the not
object to another like positive
, I could do it simply like this:
tests.utils[negative ? 'not':'positive'].exist();
But how can I dynamically exclude the not
object from the chain without an IF
statement?
My current IF
syntax works fine, but I'm curious if there is a more elegant way in JavaScript.