我看到很多代码使用这种模式:
if (typeof a.b === 'undefined') { ...
现在我正在翻译这个:(if (nil? (-.b a)) ...
这个合适吗 - 还是我失去了一些关键的数据?
我的问题是:ClojureScript中类似于JavaScript的typeof ... undefined
是什么?
我看到很多代码使用这种模式:
if (typeof a.b === 'undefined') { ...
现在我正在翻译这个:(if (nil? (-.b a)) ...
这个合适吗 - 还是我失去了一些关键的数据?
我的问题是:ClojureScript中类似于JavaScript的typeof ... undefined
是什么?
要检查可能的 undefined
引用,您可以使用cljs.core/exists?
:
(when-not (exists? js/unknownReference)
...)