我想有一些看起来像这样布尔测试作为参数
let condition = function(name, cond) {
this.name = name;
this.func = (prop) => {
if (cond) {
return true;
}
return false;
}
let snow = new condition("temperature", prop < 0);
我有一个单独的文件夹中的temerature值和功能检查,如果condition.func
返回TRUE或FALSE。例如,如果温度低于0,它就不会下雪,这意味着我会拨打condition.func(temperature)
,这将执行代码if (temperature < 0){return true}
。
问题是,当我定义雪它引发错误,道具没有定义...
我明白这是因为我正在寻找重写一个变量甚至没有初始化,但我不知道如何实现一个布尔值测试作为一个功能
我从来没有见过没有()=> {},你能解释一下道具=>道具<0实际上是一个箭头的功能? –