我有对象结构,其中utils
和utils.not
采取相同的原型(与exist
方法)。我简化它更清楚:如何在JavaScript中动态地从chaininig中排除对象?
var negative = true;
if(negative){
//when negative===true, I want to run exist() through not object
tests.utils.not.exist();
} else {
tests.utils.exist();
}
是否有任何其他的方式来排除链,而不是使用IF
not
?如果我想改变not
对象到另一个,如positive
,我能做到这一点只是这样的:
tests.utils[negative ? 'not':'positive'].exist();
但我怎么能动态地排除链not
对象? 我的IF
语法工作正常,但我只是想知道JS中是否有另一种(更优雅)的方式。
这是柴吗?如果是这样,请问一个关于柴的问题。 – Ryan