Book description
If you're ready to use Closure to build rich web applications with JavaScript, this hands-on guide has precisely what you need to learn this suite of tools in depth. Closure makes it easy for experienced JavaScript developers to write and maintain large and complex codebases—as Google has demonstrated by using Closure with Gmail, Google Docs, and Google Maps.
Author and Closure contributor Michael Bolin has included numerous code examples and best practices, as well as valuable information not available publicly until now. You'll learn all about Closure's Library, Compiler, Templates, testing framework, and Inspector—including how to minify JavaScript code with the Compiler, and why the combination of the Compiler and the Library is what sets Closure apart from other JavaScript toolkits.
- Learn how the Compiler significantly reduces the amount of JavaScript users have to download when visiting your site
- Discover several ways to use the Compiler as part of your build process
- Learn about type expressions, primitives, and common utilities
- Understand how Closure emulates classes and class-based inheritance
- Use Closure Templates on the server and the client from either JavaScript or Java
- Test and debug your JavaScript code, even when it's compiled
Publisher resources
Table of contents
- Closure: The Definitive Guide
- SPECIAL OFFER: Upgrade this ebook with O’Reilly
- Foreword
- Preface
-
1. Introduction to Closure
- Tools Overview
-
Closure Design Goals and Principles
- Reducing Compiled Code Size Is Paramount
- All Source Code Is Compiled Together
- Managing Memory Matters
- Make It Possible to Catch Errors at Compile Time
- Code Must Work Without Compilation
- Code Must Be Browser-Agnostic
- Built-in Types Should Not Be Modified
- Code Must Work Across Frames
- Tools Should Be Independent
- Downloading and Installing the Tools
- Example: Hello World
- 2. Annotations for Closure JavaScript
- 3. Closure Library Primitives
-
4. Common Utilities
- goog.string
- goog.array
- goog.object
- goog.json
-
goog.dom
- goog.dom.getElement(idOrElement)
- goog.dom.getElementsByTagNameAndClass(nodeName, className, elementToLookIn)
- goog.dom.getAncestorByTagNameAndClass(element, tag, className)
- goog.dom.createDom(nodeName, attributes, var_args)
- goog.dom.htmlToDocumentFragment(htmlString)
- goog.dom.ASSUME_QUIRKS_MODE and goog.dom.ASSUME_STANDARDS_MODE
-
goog.dom.classes
- goog.dom.classes.get(element)
- goog.dom.classes.has(element, className)
- goog.dom.classes.add(element, var_args) and goog.dom.classes.remove(element, var_args)
- goog.dom.classes.toggle(element, className)
- goog.dom.classes.swap(element, fromClass, toClass)
- goog.dom.classes.enable(element, className, enabled)
- goog.userAgent
- goog.userAgent.product
- goog.net.cookies
-
goog.style
- goog.style.getPageOffset(element)
- goog.style.getSize(element)
- goog.style.getBounds(element)
- goog.style.setOpacity(element, opacity)
- goog.style.setPreWrap(element)
- goog.style.setInlineBlock(element)
- goog.style.setUnselectable(element, unselectable, opt_noRecurse)
- goog.style.installStyles(stylesString, opt_node)
- goog.style.scrollIntoContainerView(element, container, opt_center)
- goog.functions
- 5. Classes and Inheritance
- 6. Event Management
- 7. Client-Server Communication
- 8. User Interface Components
-
9. Rich Text Editor
- Design Behind the goog.editor Package
- Creating an Editable Region
-
Extending the Editor: The Plugin System
- Registering Plugins
- Interacting with Plugins
- goog.editor.Plugin
-
Built-in Plugins
- goog.editor.plugins.BasicTextFormatter
- goog.editor.plugins.HeaderFormatter
- goog.editor.plugins.RemoveFormatting
- goog.editor.plugins.AbstractTabHandler, goog.editor.plugins.ListTabHandler, and goog.editor.plugins.SpacesTabHandler
- goog.editor.plugins.EnterHandler, goog.editor.plugins.TagOnEnterHandler, and goog.editor.plugins.Blockquote
- goog.editor.plugins.LoremIpsum
- goog.editor.plugins.UndoRedo, goog.editor.plugins.UndoRedoManager, and goog.editor.plugins.UndoRedoState
- goog.editor.plugins.AbstractDialogPlugin
- goog.editor.plugins.LinkDialogPlugin
- Custom Plugins
- UI Components
- Selections
- 10. Debugging and Logging
-
11. Closure Templates
- Limitations of Existing Template Systems
- Introducing Closure Templates
-
Creating a Template
- Declaring Templates with {namespace} and {template}
- Commenting Templates
- Overriding Line Joining with {sp} and {nil}
- Writing Raw Text with {literal}
- Building Soy Expressions
- Displaying Data with {print}
- Managing Control Flow with {if}, {elseif}, and {else}
- Advanced Conditional Handling with {switch}, {case}, and {default}
- Looping over Lists with {foreach}
- Leveraging Other Templates with {call} and {param}
- Identifying CSS Classes with {css}
- Internationalization (i18n)
- Compiling Templates
- Defining a Custom Function
- 12. Using the Compiler
- 13. Advanced Compilation
- 14. Inside the Compiler
- 15. Testing Framework
- 16. Debugging Compiled JavaScript
-
A. Inheritance Patterns in JavaScript
- Example of the Functional Pattern
- Example of the Pseudoclassical Pattern
-
Drawbacks to the Functional Pattern
- Instances of Types Take Up More Memory
- Methods Cannot Be Inlined
- Superclass Methods Cannot Be Renamed (Or Will Be Renamed Incorrectly)
- Types Cannot Be Tested Using instanceof
- Encourages Adding Properties to Function.prototype and Object.prototype
- Makes It Impossible to Update All Instances of a Type
- Naming Newly Created Objects Is Awkward
- Results in an Extra Level of Indentation
-
Potential Objections to the Pseudoclassical Pattern
- Won’t Horrible Things Happen if I Forget the New Operator?
- Didn’t Crockford Also Say I Wouldn’t Have Access to Super Methods?
- Won’t All of the Object’s Properties Be Public?
- Won’t Declaring SomeClass.prototype for Each Method and Field of SomeClass Waste Bytes?
- I Don’t Need Static Checks—My Tests Will Catch All of My Errors!
-
B. Frequently Misunderstood JavaScript Concepts
- JavaScript Objects Are Associative Arrays Whose Keys Are Always Strings
- There Are Several Ways to Look Up a Value in an Object
- Single-Quoted Strings and Double-Quoted Strings Are Equivalent
- There Are Several Ways to Define an Object Literal
- The prototype Property Is Not the Prototype You Are Looking For
- The Syntax for Defining a Function Is Significant
- What this Refers to When a Function Is Called
- The var Keyword Is Significant
- Block Scope Is Meaningless
- C. plovr
- Index
- About the Author
- Colophon
- SPECIAL OFFER: Upgrade this ebook with O’Reilly
- Copyright
Product information
- Title: Closure: The Definitive Guide
- Author(s):
- Release date: September 2010
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781449396954
You might also like
book
Etudes for ClojureScript
A short composition that provides practice material for a particular musical skill is called an étude. …
article
Communicate with Teams More Effectively
This selection of shortcuts will enable you to improve your communication, critical thinking, documentation, and networking …
article
Reinventing the Organization for GenAI and LLMs
Previous technology breakthroughs did not upend organizational structure, but generative AI and LLMs will. We now …
article
Create Effective Documentation
This selection of shortcuts will enable you to improve your communication, critical thinking, documentation, and networking …