gpt4 book ai didi

ClojureScript 检查属性是否存在于 js 对象中

转载 作者:行者123 更新时间:2023-12-02 05:37:01 25 4
gpt4 key购买 nike

如何在 clojurescript 中编写以下内容?

obj = {"a" : 4};
"a" in obj;

最佳答案

存在吗?是 added检查 undefined在 ClojureScript 中:

   (ns my.ns
(:require-macros [cljs.core :refer [exists?]]))

(if (exists? js/jQuery)
(println "jQuery"))
(println "no jQuery"))

也可以用 agetnil?避免调用 JavaScript 函数:
(def scope (js-obj))
(aset scope "var1" "Value")
(aget scope "var1") ;; "Value"
(aget scope "anotherVar") ;; nil
(nil? (aget scope "anotherVar")) ;; true

关于ClojureScript 检查属性是否存在于 js 对象中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22046889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com