mardi 1 mars 2016

Is there a way to generate a conditional expression which can be directly executed by if?

For example, can I create a method which can return me an expression that can be evaluated by if?

function getCondition(variable, value, operator)//not sure what params to pass
{
   var condition = false; //initialized to false
   //generate condition based on parameter passed
   return condition;
}

and then use it directly

if ( getCondition( a, 5, "<" ) ){ console.log("correct") }

Aucun commentaire:

Enregistrer un commentaire