将条件存储为变量.使用Javascript

Use*_*er2 5 javascript boolean eval

在javaScript中,有没有办法在变量中存储条件,然后在以后评估该条件.

我知道这可以用来完成 eval()

var condition = "(foo == pie);"
alert( eval(condition) );
Run Code Online (Sandbox Code Playgroud)

上面提醒的值将根据foo&的值而改变pie.

有没有使用相似的方法来做到这一点eval()

Den*_*ret 7

这看起来真的像是一个函数:

var conditionChecker = function(){ return foo == pie };
alert( conditionChecker() );
Run Code Online (Sandbox Code Playgroud)