Chapter 2. Interacting with JavaScript and Web Pages
Since ClojureScript compiles to JavaScript, you need to have a way to interact with native JavaScript and with web pages. In this chapter, you will discover five different ways to do this:
- Direct use of JavaScript
- The Google Closure library
- The Dommy library
- The Domina library
- The Enfocus library
Note
All of these methods are fairly “old school.” As of this writing, all the Cool Kids™ are using libraries such as Facebook’s React to handle the user interface. I still think it is useful to have knowledge of the older methods, as they might sometimes be the right tool to solve a problem. Chapter 5 describes how to work with React.
You’ll be doing the same task with each of these: calculating the number of hours of daylight based on a latitude and Julian date, as in “Étude 1-5: More Practice with def and let”. Here is the relevant HTML:
<!DOCTYPE html><html><head><title>Daylight Minutes</title><metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/></head><body><h1>Daylight Minutes</h1><p>Latitude:<inputtype="text"size="8"id="latitude"/>°<br/>Day of year:<inputtype="text"size="4"id="julian"/><br/><inputtype="button"value="Calculate"id="calculate"/></p><p>Minutes of daylight:<spanid="result"></span></p><scriptsrc="out/project_name.js"type="text/javascript"></script></body></html>
I suggest you create a new project for each of these études and copy the preceding HTML into the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access