Maintainable JavaScript

Writing Readable Code

Af Nicholas C. Zakas
Detaljer O'Reilly Media, Incorporated
ISBN 9781449327682
Sprog Engelsk
Vælg mellem
Pris 337,00 kr.
Paperback

Ikke på lager

Ikke på lager. Bestil nu og få den leveret om ca. 12 hverdage

You may have definite ideas about writing code when working alone, but team development requires that everyone use the same approach. With the JavaScript practices in this book--including code style, programming tips, and automation--you will learn how to write maintainable code that other team members can easily understand, adapt, and extend.

Author Nicholas Zakas assembled this collection of best practices as a front-end tech leader at Yahoo , after completing his own journey from solo hacker to team player. He also includes rules recommended by other industry authorities. Use these tips and techniques to help your team set aside individual preferences and function at a higher level.

  • Establish specific code conventions for your team
  • Use tools such as JSLint and JSHint to keep your team on track
  • Adopt style guidelines, such as basic formatting, to help your team produce uniform code
  • Apply several programming practices to solve problems and improve code quality
  • Create an automated JavaScript build system using a variety of utilities
  • Integrate browser-based JavaScript testing with tools such as the YUI Test Selenium Driver

Introduction;Preface; Conventions Used in This Book; Using Code Examples; Safari® Books Online; How to Contact Us;Style Guidelines;
Chapter 1: Basic Formatting;
1.1 Indentation Levels;
1.2 Statement Termination;
1.3 Line Length;
1.4 Line Breaking;
1.5 Blank Lines;
1.6 Naming;
1.7 Literal Values;
Chapter 2: Comments;
2.1 Single-Line Comments;
2.2 Multiline Comments;
2.3 Using Comments;
2.4 Documentation Comments;
Chapter 3: Statements and Expressions;
3.1 Brace Alignment;
3.2 Block Statement Spacing;
3.3 The switch Statement;
3.4 The with Statement;
3.5 The for Loop;
3.6 The for-in Loop;
Chapter 4: Variables, Functions, and Operators;
4.1 Variable Declarations;
4.2 Function Declarations;
4.3 Function Call Spacing;
4.4 Immediate Function Invocation;
4.5 Equality;
4.6 eval();
4.7 Primitive Wrapper Types;Programming Practices;
Chapter 5: Loose Coupling of UI Layers;
5.1 What Is Loose Coupling?;
5.2 Keep JavaScript Out of CSS;
5.3 Keep CSS Out of JavaScript;
5.4 Keep JavaScript Out of HTML;
5.5 Keep HTML Out of JavaScript;
Chapter 6: Avoid Globals;
6.1 The Problems with Globals;
6.2 Accidental Globals;
6.3 The One-Global Approach;
6.4 The Zero-Global Approach;
Chapter 7: Event Handling;
7.1 Classic Usage;
7.2 Rule #1: Separate Application Logic;
7.3 Rule #2: Don't Pass the Event Object Around;
Chapter 8: Avoid Null Comparisons;
8.1 Detecting Primitive Values;
8.2 Detecting Reference Values;
8.3 Detecting Properties;
Chapter 9: Separate Configuration Data from Code;
9.1 What Is Configuration Data?;
9.2 Externalizing Configuration Data;
9.3 Storing Configuration Data;
Chapter 10: Throw Your Own Errors;
10.1 The Nature of Errors;
10.2 Throwing Errors in JavaScript;
10.3 Advantages of Throwing Errors;
10.4 When to Throw Errors;
10.5 The try-catch Statement;
10.6 Error Types;
Chapter 11: Don't Modify Objects You Don't Own;
11.1 What Do You Own?;
11.2 The Rules;
11.3 Better Approaches;
11.4 A Note on Polyfills;
11.5 Preventing Modification;
Chapter 12: Browser Detection;
12.1 User-Agent Detection;
12.2 Feature Detection;
12.3 Avoid Feature Inference;
12.4 Avoid Browser Inference;
12.5 What Should You Use?;Automation;
Chapter 13: File and Directory Structure;
13.1 Best Practices;
13.2 Basic Layout;
Chapter 14: Ant;
14.1 Installation;
14.2 The Build File;
14.3 Running the Build;
14.4 Target Dependencies;
14.5 Properties;
14.6 Buildr;
Chapter 15: Validation;
15.1 Finding Files;
15.2 The Task;
15.3 Improving the Target;
15.4 Other Improvements;
15.5 Buildr Task;
Chapter 16: Concatenation and Baking;
16.1 The Task;
16.2 Line Endings;
16.3 Headers and Footers;
16.4 Baking Files;
Chapter 17: Minification and Compression;
17.1 Minification;
17.2 Compression;
Chapter 18: Documentation;
18.1 JSDoc Toolkit;
18.2 YUI Doc;
Chapter 19: Automated Testing;
19.1 YUI Test Selenium Driver;
19.2 Yeti;
19.3 PhantomJS;
19.4 JsTestDriver;
Chapter 20: Putting It Together;
20.1 Missing Pieces;
20.2 Planning the Build;
20.3 Using a CI System;JavaScript Style Guide; Indentation; Line Length; Primitive Literals; Operator Spacing; Parentheses Spacing; Object Literals; Comments; Variable Declarations; Function Declarations; Naming; Strict Mode; Assignments; Equality Operators; Ternary Operator; Statements; White Space; Things to Avoid;JavaScript Tools; Build Tools; Documentation Generators; Linting Tools; Minification Tools; Testing Tools;Colophon;