VDone Demo VDone Demo
Home
  • Articles

    • JavaScript
  • Study Notes

    • JavaScript Tutorial
    • Professional JavaScript
    • ES6 Tutorial
    • Vue
    • React
    • TypeScript: Build Axios from Scratch
    • Git
    • TypeScript
    • JS Design Patterns
  • HTML
  • CSS
  • Technical Docs
  • GitHub Tips
  • Node.js
  • Blog Setup
  • Learning
  • Interviews
  • Miscellaneous
  • Practical Tips
  • Friends
About
Bookmarks
  • Categories
  • Tags
  • Archives
GitHub (opens new window)

Nikolay Tuzov

Backend Developer
Home
  • Articles

    • JavaScript
  • Study Notes

    • JavaScript Tutorial
    • Professional JavaScript
    • ES6 Tutorial
    • Vue
    • React
    • TypeScript: Build Axios from Scratch
    • Git
    • TypeScript
    • JS Design Patterns
  • HTML
  • CSS
  • Technical Docs
  • GitHub Tips
  • Node.js
  • Blog Setup
  • Learning
  • Interviews
  • Miscellaneous
  • Practical Tips
  • Friends
About
Bookmarks
  • Categories
  • Tags
  • Archives
GitHub (opens new window)
  • JavaScript文章

  • 学习笔记

    • JavaScript Tutorial - Notes
    • Professional JavaScript for Web Developers - Notes
    • ES6 Tutorial - Notes
    • Vue - Notes
    • React - Notes
    • TypeScript - Implementing axios from Scratch
    • Git - Study Notes
    • TypeScript Notes
    • Mini Program Notes
    • JS Design Patterns Summary Notes
      • Introduction: The Growth Path of a Frontend Engineer
      • The "Dao" of Design Patterns
        • Core Concept
      • The "Techniques" of Design Patterns
        • Creational
        • Structural
        • Behavioral
      • Summary:
      • Creational: Factory Pattern - Simple Factory -- Distinguishing "What Changes and What Doesn't"
        • Constructor Pattern
        • Simple Factory Pattern
  • 前端
  • 学习笔记
xugaoyi
2021-02-27
Contents

JS Design Patterns Summary Notes

# JS Design Patterns Summary Notes

# Introduction: The Growth Path of a Frontend Engineer

What fundamentally defines a frontend engineer is not the ever-changing technology landscape, but the things that don't change.

The so-called "things that don't change" are the ability to master technology.

Specifically, this breaks down into three levels:

  • Being able to solve concrete problems with robust code;
  • Being able to handle complex systems with abstract thinking;
  • Being able to plan larger-scale business with engineering mindset.

A person's theoretical foundation forms their baseline -- the stronger the theory, the higher the baseline. Set a goal and build a ladder upward, and reaching the goal becomes a matter of time. Many self-taught engineers spend their entire careers without reaching the baseline of an excellent engineer. Many of the profound insights they painstakingly arrive at are just natural knowledge to formally trained engineers. -- Wu Jun

# The "Dao" of Design Patterns

  • Design patterns are about "borrowing established solutions." Like using mathematical formulas -- you don't derive the formula from scratch every time.

# Core Concept

  • The core concept of design patterns -- encapsulate what varies
  • Ensure maintainability and extensibility.
  • Separate what changes from what doesn't, ensuring the changing parts remain flexible and the unchanging parts remain stable -- this is what makes code "robust."

# The "Techniques" of Design Patterns

The classic 23 design patterns, categorized as Creational, Structural, and Behavioral.

# Creational

  1. Singleton Pattern
  2. Prototype Pattern
  3. Constructor Pattern
  4. Factory Pattern
  5. Abstract Factory Pattern

# Structural

  1. Bridge Pattern
  2. Facade Pattern
  3. Composite Pattern
  4. Decorator Pattern
  5. Adapter Pattern
  6. Proxy Pattern
  7. Flyweight Pattern

# Behavioral

  1. Iterator Pattern
  2. Interpreter Pattern
  3. Observer Pattern
  4. Visitor Pattern
  5. State Pattern
  6. Memento Pattern
  7. Strategy Pattern
  8. Template Method Pattern
  9. Chain of Responsibility Pattern
  10. Command Pattern

# Summary:

  • Creational patterns encapsulate the variation in the process of creating objects.

  • Structural patterns encapsulate the variation in how objects are composed. Their purpose is to flexibly express the cooperation and dependency relationships between objects.

  • Behavioral patterns abstract out the ever-changing behaviors of objects, ensuring safe and convenient modification.

# Creational: Factory Pattern - Simple Factory -- Distinguishing "What Changes and What Doesn't"

First, understand the Constructor Pattern. In JavaScript, a constructor function is a constructor. Using constructor functions means using the Constructor Pattern.

# Constructor Pattern

function User(name, age, career){
  this.name = name
  this.age = age
  this.career = career
}
const user = New User('Zhang San', 18, 'Frontend Engineer')
1
2
3
4
5
6

What changes and what doesn't: the user's attributes (name, age, career) don't change -- that's the commonality. What changes are the attribute values -- that's the individuality.

# Simple Factory Pattern

function User(name , age, career, work) {
    this.name = name
    this.age = age
    this.career = career
    this.work = work
}

// Factory function (extract the changing parts into a separate function)
function Factory(name, age, career) {
    let work
    switch(career) {
        case 'coder':
            work =  ['Write code','Write system design', 'Fix bugs']
            break
        case 'product manager':
            work = ['Book meeting rooms', 'Write PRDs', 'Chase developers']
            break
        case 'boss':
            work = ['Drink tea', 'Read newspapers', 'Meet clients']

        // Assign responsibilities for other roles
        //case 'xxx':
            //...

    return new User(name, age, career, work)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

The Factory Pattern encapsulates the process of creating objects into a separate function.

Edit (opens new window)
#Design Patterns
Last Updated: 2026/03/21, 12:14:36
Mini Program Notes

← Mini Program Notes

Recent Updates
01
How I Discovered Disposable Email — A True Story
06-12
02
Animations in Grid Layout
09-15
03
Renaming a Git Branch
08-11
More Articles >
Theme by VDone | Copyright © 2026-2026 Nikolay Tuzov | MIT License | Telegram
  • Auto
  • Light Mode
  • Dark Mode
  • Reading Mode