Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Google Closure Library

Shaun Mahood edited this pageMar 18, 2017 ·13 revisions

DEPRECATION NOTICE: Please do not edit this wiki. Instead submit pull requests tohttps://github.com/clojure/clojurescript-site

The up to date version of this page can be found athttps://clojurescript.org/reference/google-closure-library

ClojureScript projects always auto-include theGoogle Closure Library, a massive library built and used by Google on many of their products (Gmail, Docs, etc). It has low-level utilities for DOM manipulation, server communication, animation, data structures, unit testing, rich-text editing, and UI widgets/controls.

Try the wrapper libraries first!

You may first want to consider the following ClojureScript libraries which wrapsome functionality from Google Closure Library. Their source code also servesas good examples of how to use Closure directly.

ClojureScript wrapperClosure Libraries
cljs-timegoog.date
cljs-httpgoog.net,goog.uri
cljs-ajaxgoog.net,goog.uri,goog.json
cuerdasgoog.string

* included in ClojureScript's core library

Using Google Closure directly

Some helpful blog posts:

To use Google Closure in your ClojureScript code, the rule is to use:

  • :import for Closure classes (which are also namespaces, likegoog.Uri) and enums
  • :require for everything else

Import a class

This is only for when you would like to refer directly to a class which isalso a namespace, otherwise just use:require in yourns form or use therequire REPL helper.

(nsexample.core  (:import goog.Uri))
;; in REPL(import 'goog.Uri)(Uri."http://example.com");;=> #<http://example.com>

Import an enum

(nsexample.core  (:import [goog.events EventType]))
;; in REPL(import '[goog.events EventType])EventType.CLICK;;=> "click"

Requiring a function

(nsexample.core  (:require [goog.math:as math]))
;; in REPL(require '[goog.math:as math])(math/clamp-105);;=> 0
⚠️Sometimes symbols are __not auto-included__ when requiring their parent namespace. This happens when those symbols are in their own file and require specific inclusion
(nsexample.core  (:require    [goog.string:as gstring]    goog.string.format))
;; in REPL(require '[goog.string:as gstring])(require 'goog.string.format)(goog.string.format"%05d"123);;=> 00123;; or use the alias(gstring/format"%05d"123);;=> 00123

Searching for Examples

You can look forcljs files on Github that usegoog.dom with the following search:

Search GitHub: "[goog.dom extension:cljs](https://github.com/search?utf8=%E2%9C%93&q=goog.dom+extension%3Acljs&type=Code&ref=searchresults)"

Or you can search Google Closure Library on Github for keywords pertaining to a function it might have:

Search Closure Library on Github: "[hours minutes](https://github.com/google/closure-library/search?utf8=%E2%9C%93&q=hours+minutes)"
Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp