Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 JDK 7 中使用 JavaScript 引擎。有没有办法评估一个表达式,比如a||b如果a和b未定义,而不是抛出异常ReferenceError: "a" is not defined.?
a||b
a
b
ReferenceError: "a" is not defined.
我不认为这是可能的。
我采取了以下方法来实现我想要的。我正在评估表达式,如果该表达式失败,我会将未定义的变量添加到上下文中并尝试再次重新评估。