神刀安全网

Clojurescript’s namespaces

If you are like me, namespaces in clojurescript is a question that has returned yourself several times during learning clojurescript. Let’s clarify usingKLIPSE:

As you know, javascript doesn’t support namespaces, the workaround consists to use an object that will take your namespace’s role. All variables of your javascript namespace will be nested in this object.

You’ve probably already understood that clojurescript compiler use simply the same trick! So goog.provide function initialize the my_ns object and you can find variables x and y nested inside it.

goog.require function includes the namespace you need need to use in your code. It receive a string with several dot-separated levels. Each level is a nested part of the javascript object to include. In this case, require will include all the object cljs.core .

You can learn more about google closure library here .

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Clojurescript’s namespaces

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮