Fabian Jakobs presents on JavaScript tooling for larger applications. He demonstrates linkers to detect dependencies and optimize builds, linters like JSLint and ecmalint to find errors, API documentation tools, and packers/minifiers like YUI Compressor to optimize files for deployment. He shows examples of these tools on a sample filter application to illustrate professional JavaScript tooling.
2. About me
• Fabian Jakobs
<fabian.jakobs@1und1.de>
• JavaScript Framework developer
at 1&1
– Framework architect of the
Javascript GUI Framework
qooxdoo
Fabian Jakobs | 1&1
3. Overview
• Professional tooling for JavaScript
• Focus on larger JavaScript based applications
• Will demonstrate the presented techniques on
a simple example application
Fabian Jakobs | 1&1
4. Example Program
• Performs „Filter-as-you-
type“
• Separation of
– Content (HTML)
– Style (CSS)
– Behavior (JavaScript)
• Uses qooxdoo DOM API
• No qooxdoo GUI
application Demo
Fabian Jakobs | 1&1
9. What is under the hood?
ShrinkSafe JSLint
qooxdoo tools
YUI Compressor (JavaScript
(Python JS parser)
(Rhino) JS parser)
Syntax Tree
JSMin
Parser
JSDoc
Tokens
Scanner
(RegExp)
JavaScript
Fabian Jakobs | 1&1
10. Linker
• Detect dependencies between JavaScript fles
• Sorted list of fles to include
• Generate an optimized version of the
application
Fabian Jakobs | 1&1
13. Linker – Common Scenario
• Scenario
– Use of a pre build version of the framework used
– Manage include list of own JavaScript fles manually
• Problems
– You always include the full framework even if only parts of it
are used
– managing dependencies manually doesn't scale
– Needs separate solution for deployment (combination of
fles)
Fabian Jakobs | 1&1
14. Linker - Solution
• Solution
– (semi-) automatic detection of dependencies
• needs knowledge about the Framework
– Generation of loader scripts
– Generation of „compiled“ application fles
• Implementations
– dojo build system
• evaluates „dojo.require()“
– qooxdoo
• „knows“ qooxdoo class defnitions
Fabian Jakobs | 1&1
16. Lint
• Static code analysis
– fnd common coding mistakes
– enforce coding guidelines
• Especially useful in dynamic languages, where
errors
– often occur only at runtime
– only under certain conditions
– have strange side effects and are hard to fnd
Fabian Jakobs | 1&1
17. Lint – Can you fnd all errors?
• This code is full of
– errors
– bad JavaScript style
• Demonstrate two lint tools
– JSLint by Douglas Crockford
– ecmalint (part of qooxdoo)
• Other tools
– JavaScript Lint
– YUI packer (-v parameter)
Fabian Jakobs | 1&1
18. Lint – Ecmalint
• Finds
– errors related to variable scope
• undefned variables
• unused variables
– redefnition of map keys
– deprecated methods (eval,
alert, ...)
• Part of qooxdoo
• Works with any JavaScript
Fabian Jakobs | 1&1
19. Lint – Ecmalint
Use of undefined or global identifier 'xO'
Unused identifier 'j'
Use of undefined or global identifier 'i'
Map key 'add' redefined
Use of deprecated global identifier 'alert'
Fabian Jakobs | 1&1
20. Lint – JSLint
• Checks for bad coding style
• by Douglas Crockford
– “Will hurt your feelings”
• Reports
– Missing semicolons
– Unreachable code
– Missing blocks
– Many more
Fabian Jakobs | 1&1
21. Lint – JSLint
Missing semicolon.
Expected '{' and instead saw 'sum'.
Use '===' to compare with '0'.
Expected '{' and instead saw 'throw'.
Missing semicolon.
Unreachable 'return' after 'return'.
Fabian Jakobs | 1&1
22. Lint – Summary
• Lint tools can help fnding bugs early
• Should be run regularly
• Should be integrated into the build system
BUT: Cannot replace testing!
Fabian Jakobs | 1&1
24. API Documentation
• Generate API documentation
• Most JavaScript Frameworks have API
documentation for their classes
• Must understand the framework
Fabian Jakobs | 1&1
25. API Documentation – JSDoc
• Non framework tool
• Uses JavaDoc like documentation comments
• Only basic JavaScript OO features
• Does not understand
– OO notation of most frameworks
– OO notation of qooxdoo
• Generates boring static HTML :-)
Fabian Jakobs | 1&1