Some common Javascript patterns
Design patterns are reusable solutions to commonly occurring problems in software design. They are both exciting and a fascinating topic to explore in any programming language. Design patterns also provide us a common vocabulary to describe solutions. This can be significantly simpler than describing syntax and semantics when we're attempting to convey a way of structuring a solution in code form to others.
A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer can use to solve common problems when designing an application or system.
I created this course as part of a series of small tutorials taught in my workplace. The repository contains an code example of each of the design patterns discussed in the course "Common Javascript patterns"
Features
- AMD (RequireJS)
Creational Design Patterns
- The Factory Pattern
Structural Patterns
- The Adapter Pattern
- The Proxy Pattern
- The Facade Pattern
- The Decorator Pattern
- The Composite Pattern
Behavioural Patterns
- The Chain of Responsibility Pattern
- The Mediator Pattern
- The Iterator Pattern
- The Publisher/Subscriber Pattern
- The Strategy Pattern
- The Observer Pattern
- Clone repository to your machine
git clone https://github.com/jasancheg/js-design-patterns-into-practice.git
- Run
cd js-design-patterns-into-practice
- Run
bower install
- Open index.html in your browser and open the browser's console
- Use the global runExample() method to run one of the examples
runExample('factory')
Valid example names (to be passed as a string to the runExample() function) are:
Name | example |
---|---|
factory |
runExample('factory') |
iterator |
runExample('iterator') |
pubsub |
runExample('pubsub') |
facade |
runExample('facade') |
strategy |
runExample('strategy') |
decorator |
runExample('decorator') |
observer |
runExample('observer') |
adapter |
runExample('adapter') |
cor |
runExample('cor') |
composite |
runExample('composite') |
mediator |
runExample('mediator') |
proxy |
runExample('proxy') |
*. Use the global runExample() method to run one of the examples
runExample('factory')
MIT © Jose Antonio Sanchez