Closure: The Definitive Guide. Google Tools to Add Power to Your JavaScript - Helion
ISBN: 978-14-493-9695-4
stron: 592, Format: ebook
Data wydania: 2010-09-08
Księgarnia: Helion
Cena książki: 139,00 zł
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
Osoby które kupowały "Closure: The Definitive Guide. Google Tools to Add Power to Your JavaScript", wybierały także:
- D3.js w akcji 67,42 zł, (20,90 zł -69%)
- Tablice informatyczne. Node.js 16,86 zł, (5,90 zł -65%)
- React i GatsbyJS. Kurs video. Nowoczesne strony internetowe w oparciu o headless CMS i GraphQL 148,98 zł, (59,59 zł -60%)
- TypeScript i React. Kurs video. Tworzenie nowoczesnych komponent 129,00 zł, (51,60 zł -60%)
- Vue.js w praktyce. Kurs video. Poznaj narz 148,98 zł, (59,59 zł -60%)
Spis treści
Closure: The Definitive Guide. Google Tools to Add Power to Your JavaScript eBook -- spis treści
- Closure: The Definitive Guide
- SPECIAL OFFER: Upgrade this ebook with OReilly
- Foreword
- Preface
- My Experiences with Closure
- Audience
- ECMAScript Versus JavaScript
- Using This Book
- Conventions Used in This Book
- Using Code Examples
- Safari Books Online
- How to Contact Us
- Acknowledgments
- 1. Introduction to Closure
- Tools Overview
- Closure Library
- Closure Templates
- Closure Compiler
- Closure Testing Framework
- Closure Inspector
- 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
- Closure Library and Closure Testing Framework
- Closure Templates
- Closure Compiler
- Closure Inspector
- Example: Hello World
- Closure Library
- Closure Templates
- Closure Compiler
- Closure Testing Framework
- Closure Inspector
- Tools Overview
- 2. Annotations for Closure JavaScript
- JSDoc Tags
- Type Expressions
- Simple Types and Union Types
- Function Types
- Record Types
- Special @param Types
- Specifying optional parameters
- Optional parameters
- Variable number of parameters
- Subtypes and Type Conversion
- The ALL Type
- JSDoc Tags That Do Not Deal with Types
- Constants
- Deprecated Members
- License and Copyright Information
- Is All of This Really Necessary?
- 3. Closure Library Primitives
- Dependency Management
- calcdeps.py
- goog.global
- Finer details of goog.global
- COMPILED
- goog.provide(namespace)
- Motivation behind goog.provide()
- goog.require(namespace)
- goog.addDependency(relativePath, provides, requires)
- Function Currying
- goog.partial(functionToCall, ...)
- goog.bind(functionToCall, selfObject, ...)
- Exports
- goog.getObjectByName(name, opt_object)
- goog.exportProperty(object, propertyName, value)
- goog.exportSymbol(publicPath, object, opt_objectToExportTo)
- Type Assertions
- goog.typeOf(value)
- goog.isDef(value)
- goog.isNull(value)
- goog.isDefAndNotNull(value)
- goog.isArray(obj)
- goog.isArrayLike(obj)
- goog.isDateLike(obj)
- goog.isString(obj), goog.isBoolean(obj), goog.isNumber(obj)
- goog.isFunction(obj)
- goog.isObject(obj)
- Unique Identifiers
- goog.getUid(obj)
- goog.removeUid(obj)
- Internationalization (i18n)
- goog.LOCALE
- goog.getMsg(str, opt_values)
- Object Orientation
- goog.inherits(childConstructorFunction, parentConstructorFunction)
- goog.base(self, opt_methodName, var_args)
- goog.nullFunction
- goog.abstractMethod
- goog.addSingletonGetter(constructorFunction)
- Additional Utilities
- goog.DEBUG
- goog.now()
- goog.globalEval(script)
- goog.getCssName(className, opt_modifier), goog.setCssNameMapping(mapping)
- Dependency Management
- 4. Common Utilities
- goog.string
- goog.string.htmlEscape(str, opt_isLikelyToContainHtmlChars)
- goog.string.regExpEscape(str)
- goog.string.whitespaceEscape(str, opt_xml)
- goog.string.compareVersions(version1, version2)
- goog.string.hashCode(str)
- goog.array
- goog.array.forEach(arr, func, opt_obj)
- Using Iterative goog.array Functions in a Method
- goog.object
- goog.object.get(obj, key, opt_value)
- goog.setIfUndefined(obj, key, value)
- goog.object.transpose(obj)
- goog.json
- goog.json.parse(str)
- goog.json.unsafeParse(str)
- goog.json.serialize(obj)
- 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
- Rendering Engine Constants
- Platform Constants
- goog.userAgent.isVersion(version)
- goog.userAgent.product
- goog.net.cookies
- goog.net.cookies.isEnabled()
- goog.net.cookies.set(name, value, opt_maxAge, opt_path, opt_domain)
- goog.net.cookies.get(name, opt_default)
- goog.net.cookies.remove(name, opt_path, opt_domain)
- 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
- goog.functions.TRUE
- goog.functions.constant(value)
- goog.functions.error(message)
- goog.string
- 5. Classes and Inheritance
- Example of a Class in Closure
- Closure JavaScript Example
- Equivalent Example in Java
- Static Members
- Singleton Pattern
- Example of a Subclass in Closure
- Closure JavaScript Example
- Equivalent Example in Java
- Declaring Fields in Subclasses
- @override and @inheritDoc
- Using goog.base() to Simplify Calls to the Superclass
- Abstract Methods
- Example of an Interface in Closure
- Multiple Inheritance
- Enums
- goog.Disposable
- Overriding disposeInternal()
- Example of a Class in Closure
- 6. Event Management
- A Brief History of Browser Event Models
- Closure Provides a Consistent DOM Level 2 Events API Across Browsers
- goog.events.listen()
- goog.events.EventTarget
- goog.events.Event
- goog.events.EventHandler
- Handling Keyboard Events
- 7. Client-Server Communication
- Server Requests
- goog.net.XmlHttp
- goog.net.XhrIo
- Customizing the request
- Handling the response
- goog.net.XhrManager
- goog.Uri and goog.uri.utils
- Resource Loading and Monitoring
- goog.net.BulkLoader
- goog.net.ImageLoader
- goog.net.IframeLoadMonitor
- goog.net.MultiIframeLoadMonitor
- goog.net.NetworkTester
- Cross-Domain Communication
- goog.net.jsonp
- goog.net.xpc
- Uploading Files
- Comet
- Server Requests
- 8. User Interface Components
- Design Behind the goog.ui Package
- goog.ui.Component
- Basic Life Cycle
- Instantiation
- Display
- Disposal
- Components with Children
- Adding a child
- Removing a child
- Accessor methods
- Events
- States
- Errors
- Basic Life Cycle
- goog.ui.Control
- Handling User Input
- Managing State
- Delegating to the Renderer
- Associating presentation logic with a state
- goog.ui.registry
- goog.ui.decorate
- Example: Responding to a Mouseover Event
- goog.ui.Container
- Using Common Components
- Pulling in CSS
- goog-inline-block
- Example of Rendering a Component: goog.ui.ComboBox
- Example of Decorating a Control: goog.ui.Button and goog.ui.CustomButton
- goog.ui.Button
- goog.ui.CustomButton
- Creating Custom Components
- example.Checklist and example.ChecklistItem
- example.ui.ChecklistItem and example.ui.ChecklistItemRenderer
- example.ui.Label
- example.ui.Checklist and example.ui.ChecklistRenderer
- Rendering Example
- Decorating Example
- Conclusions
- 9. Rich Text Editor
- Design Behind the goog.editor Package
- Trade-offs: Control, Code Size, and Performance
- goog.editor.BrowserFeature
- Creating an Editable Region
- goog.editor.Field
- Instantiation
- Making editable
- Getting and setting the fields contents
- Change events
- Events
- State
- Common setters and accessors
- goog.editor.SeamlessField
- Controlling the height of a seamless field
- Controlling the styles of a seamless field
- goog.editor.Field
- Extending the Editor: The Plugin System
- Registering Plugins
- Interacting with PluginsÂ
- goog.editor.Plugin
- Handling key events
- Executing commands
- Handling selection changes
- Transforming field contents
- Advanced customization
- 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
- Creating custom plugins
- Creating a custom dialog plugin
- UI Components
- Dialogs
- goog.ui.editor.AbstractDialog
- Creating a custom dialog
- Toolbar
- goog.ui.editor.DefaultToolbar
- goog.ui.editor.ToolbarFactory
- goog.ui.editor.ToolbarController
- Creating a custom toolbar button
- Styling the toolbar
- Dialogs
- Selections
- goog.dom.Range
- goog.dom.AbstractRange
- Getting endpoints of a range
- Setting endpoints of a range
- Extracting data from a range
- Changing the DOM
- Saving and restoring selections
- Iterating
- Other goodies
- goog.editor.range
- Placing the cursor
- Visually equivalent positions
- goog.editor.range.Point
- Normalizing
- Design Behind the goog.editor Package
- 10. Debugging and Logging
- Creating Logging Information
- goog.debug.LogRecord
- goog.debug.Logger.Level
- goog.debug.Logger
- Creating a logger
- Logging a message
- Logger hierarchy
- Displaying Logging Information
- goog.debug.Console
- goog.debug.DivConsole
- goog.debug.DebugWindow
- goog.debug.FancyWindow
- Profiling JavaScript Code
- Reporting JavaScript Errors
- Creating Logging Information
- 11. Closure Templates
- Limitations of Existing Template Systems
- Server-Side Templates
- Client-Side Templates
- 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
- Referencing map and list data
- Referencing global variables
- 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
- Compiling a Template for JavaScript
- Compilation
- Usage
- Compiling a Template for Java
- Compilation
- Usage
- Compiling a Template for JavaScript
- Defining a Custom Function
- Limitations of Existing Template Systems
- 12. Using the Compiler
- Benefits of Using the Compiler
- Reducing Code Size
- Catching Errors at Compile Time
- Protecting Code Through Obfuscation
- How the Compiler Works
- Compiler Options
- Compilation Levels
- Whitespace Only
- Simple
- Advanced
- Formatting Options
- Pretty print
- Print input delimiter
- Warning Levels
- Quiet
- Default
- Verbose
- Compilation Levels
- Running the Compiler
- Closure Compiler Service UI
- Closure Compiler Service API
- Closure Compiler Application
- Fine-grained control over warnings and errors
- Compile-time defines
- Output wrapper
- Programmatic Java API
- Integrating the Compiler into a Build Process
- Partitioning Compiled Code into Modules
- Introducing the Application Code
- app.js
- settings.js
- api.js
- Introducing the Module Loading Code
- app_init.js
- settings_init.js
- api_init.js
- Partitioning the Input
- --module flag
- --module_output_path_prefix flag
- Loading the Modules
- Refining the Partitioning
- Introducing the Application Code
- Benefits of Using the Compiler
- 13. Advanced Compilation
- What Happens During Compilation
- Externs and Exports
- Using custom externs
- Externs and the compilation model
- Externs versus exports
- Exporting methods for a public API
- Property Flattening
- Property Renaming
- Externs and Exports
- Preparing Code for the Compiler
- Input Language
- Programmatic Evaluation of Strings of JavaScript Code
- Never Use the with Keyword
- Checks Provided by the Compiler
- Type Checking
- Unknown type warnings
- Access Controls
- Visibility
- Deprecated members
- Type Checking
- Optimizations Performed by the Compiler
- Processing Closure Primitives
- goog.provide
- goog.require
- goog.addDependency
- Devirtualizing Prototype Methods
- Inlining
- Constants and folding
- Variables
- Functions
- Processing Closure Primitives
- What Happens During Compilation
- 14. Inside the Compiler
- Tour of the Codebase
- Getting and Building the Compiler
- Compiler.java
- CompilerPass.java
- JSSourceFile.java
- CompilerOptions.java
- CompilationLevel.java
- WarningLevel.java
- PassFactory.java
- DefaultPassConfig.java
- CommandLineRunner.java
- com.google.common.collect
- Hidden Options
- Checks
- checkEs5Strict
- checkMissingReturn
- codingConvention
- reportUnknownTypes
- Renaming
- aliasKeywords
- aliasAllStrings
- aliasExternals
- exportTestFunctions
- Optimizations
- stripTypePrefixes
- stripNameSuffixes
- setIdGenerators
- disambiguateProperties
- ambiguateProperties
- Output
- lineBreak
- inputDelimiter
- colorizeErrorOutput
- externExports
- Checks
- Example: Extending CommandLineRunner
- Example: Visualizing the AST Using DOT
- What Is DOT?
- Converting the AST to DOT
- Hooking into MyCommandLineRunner
- Example: Creating a Compiler Check
- Example: Creating a Compiler Optimization
- Tour of the Codebase
- 15. Testing Framework
- Creating Your First Test
- Example: Testing an Email Validator
- Creating the initial set of tests
- Creating the HTML file to run the test
- Getting the tests to pass
- Creating more tests
- Assertions
- Life Cycle of a Test Case
- Differences from JsUnit
- Example: Testing an Email Validator
- Mock Objects
- goog.testing.PropertyReplacer
- goog.testing.PseudoRandom
- goog.testing.MockClock
- Testing to Ensure That an Error Is Thrown
- Testing Input Events
- Testing Asynchronous Behavior
- goog.testing.ContinuationTestCase
- waitForTimeout(continuation, duration)
- waitForEvent(eventTarget, eventType, continuation)
- waitForCondition(condition, continuation, interval, maxTimeout)
- goog.testing.AsyncTestCase
- goog.testing.ContinuationTestCase
- Running a Single Test
- Running Multiple Tests
- Automating Tests
- System Testing
- Creating Your First Test
- 16. Debugging Compiled JavaScript
- Verify That the Error Occurs in Uncompiled Mode
- Format Compiled Code for Debugging
- Compile with --debug=true
- Use the Closure Inspector
- 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
- Wont Horrible Things Happen if I Forget the New Operator?
- Didnt Crockford Also Say I Wouldnt Have Access to Super Methods?
- Wont All of the Objects Properties Be Public?
- Wont Declaring SomeClass.prototype for Each Method and Field of SomeClass Waste Bytes?
- I Dont Need Static ChecksMy 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
- Getting Started with plovr
- Config Files
- Build Command
- Serve Command
- Displaying Compiler Errors
- Auditing Compiled Code Size
- Generating Externs from Exports
- Generating a Source Map
- Index
- About the Author
- Colophon
- SPECIAL OFFER: Upgrade this ebook with OReilly
- Copyright