- Chapter 1: Introduction
- Patterns
- JavaScript concepts
- ECMAScript 5
- JSLint
- The Console
- Chapter 2: Essentials
- Writing Maintainable Code
- Minimizing Globals
- for Loops
- for-in Loops
- (Not) Augmenting Built-in Prototypes
- switch Pattern
- Avoiding Implied Typecasting
- Avoiding eval()
- Number Conversions with parseInt()
- Coding Conventions
- Naming Conventions
- Writing Comments
- Writing API Docs
- Writing to Be Read
- Peer Reviews
- Minify...In Production
- Run JSLint
- Summary
- Chapter 3: Literals and Constructors
- Object Literal
- Custom Constructor Funtions
- Patterns for Enforcing new
- Array Literal
- JSON
- Regular Expression Literal
- Primitive Wrappers
- Error Objects
- Summary
- Chapter 4: Functions
- Background
- Callback pattern
- Returning functions
- Self-Defining functions
- Immediate functions
- Immediate Object initialization
- Init-Time Branching
- Function Properties - A Memoization Pattern
- Configuration Objects
- Curry
- Summary
- Chapter 5: Object Creation Patterns
- Namespace Pattern
- Declaring Dependencies
- Private Properties and Methods
- Module Pattern
- Sandbox Pattern
- Static Members
- Object Constants
- Chaining Pattern
-
method()
Method - Summary
Last active
August 29, 2015 14:01
-
-
Save muhammadghazali/c7ab0ff528b1c48ee3de to your computer and use it in GitHub Desktop.
My reading progress on JavaScript Patterns (http://shop.oreilly.com/product/9780596806767.do)
Chapter 4: Summary
Useful patterns in JavaScript function:
- API patterns
- Initialization patterns
- Performance patterns
API patterns
These pattern help you provide better and cleaner interfaces to your functions. These patterns include:
- Callback patterns. Pass a function as an argument
- Configuration objects. Help keep the number of arguments to a function under control
- Returning functions. When the return value of one function is another function
- Currying. When new functions are created based on existing ones plus a partial list of arguments
Initialization patterns
These pattern help you perform initialization and setup tasks (very common to web pages and applications) in a clearer, structured way without polluting the global namespace with temporary variables. These patterns include:
- Immediate functions. Execute as soon as they are defined
- Immediate object initialization. Initialization tasks structured in an anonymous object that provides a method to be called immediately.
- Init-time branching. Helps branch code only once during initial code execution, as opposed to many times later during the life of the application.
Performance patterns
These patterns help speed up the code. These include:
- Memoization. Using function properties so that computed values are not computed again.
- Self-defining functions. Overwrite themselves with new bodies to do less work from the second invocation and after.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Chapter 4: Configuration objects
Use configuration object pattern to provide cleaner APIs.
An example of function without configuration objects pattern:
An example of function with configuration objects pattern:
The pros of the configuration objects pattern are:
The cons of the configuration objects are: