Clojuratcript للتحقق مما إذا كان هناك عقار موجود في كائن JS
-
21-12-2019 - |
سؤال
كيف أكتب ما يلي في Clojurescript؟
giveacodicetagpre.المحلول
متابعة الطريقة المقبولة حتى الآن للتحقق مما إذا كانت خاصية كائن JS موجودة باستخدام الطريقة " hasownproperty " يمكننا ترجمة ذلك على النحو التالي:
giveacodicetagpre.نصائح أخرى
exists? was added to check for undefined
in ClojureScript :
(ns my.ns
(:require-macros [cljs.core :refer [exists?]]))
(if (exists? js/jQuery)
(println "jQuery"))
(println "no jQuery"))
One can also use aget
and nil?
to avoid calling JavaScript functions :
(def scope (js-obj))
(aset scope "var1" "Value")
(aget scope "var1") ;; "Value"
(aget scope "anotherVar") ;; nil
(nil? (aget scope "anotherVar")) ;; true
لا تنتمي إلى StackOverflow