Detailed Explanation of JavaScript Framework Design Patterns

Detailed Explanation of JavaScript Framework Design Patterns

mvc

insert image description here

Model(模型) - A model represents an object or JAVA POJO that stores and retrieves data. It can also contain logic to update the controller when the data changes.

View(視圖) - A view represents the visualization of the data contained in a model.

Controller(控制器) - The controller acts on the model and the view. It controls the flow of data to the model objects and updates the view when the data changes. It separates the view from the model.

It is one-way

mvp

insert image description here

The core of MVP lies in the presenter layer. The core of this layer is the operation of DOM elements. Taking the implementation of list page with jQuery as an example, the presenter mainly combines the data in the Model with the HTML tags through a loop and adds them to the View.

mvvm

insert image description here

The core of mvvm lies in the Model layer, the core of which is the operation on data. Compared with the mvp mode, our coding focus has shifted from the operation on dom to the operation on data. The VM layer displays data to the view layer and passes the data of the view layer to the Model layer. Vue is a typical example of viewModel

The source of Vue

Vue draws on react's virtual dom technology and angular's ng-directive technology

spa mpa

MPA: multi-page application

Features: The first loading is faster, and the subsequent loading is slower. The initial development cost is low, but the later maintenance cost is high.

SPA: single page application

The first load is slower, and the subsequent loads are faster. The initial development cost is high, but the later maintenance cost is low. (Mainly reused more)

createElement

var li = document.createElement(ele,src,content);
//ele The element to be created //src The attributes of the element //content The content of the elementvar li = document.createElement('li',{className='list-li'},'123');
<li className="list-li">123<li>

class

class Person {
   constructor(x,y) {
      this.x = x;
   }
   add() {
      console.log(this.x);
   }
}
var person = new Person(1,2);
typeof Person // function The essence of the class is a constructor Person === Person.prototype.constructor //true The class points to the prototype of the constructor person.hasOwnProperty(x); //true
person.hasOwnProperty(y); //false
person.hasOwnProperty(add); // false
This in the constructor points to the instantiated object, so x is a property of person and y and add are equivalent to adding to Person.prototype person.__proto__.hasOwnProperty(add) //true

The function in the class is equivalent to adding it to the prototype of the constructor.

Summarize

This article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • JavaScript design pattern strategy pattern implementation principle detailed explanation
  • JavaScript Design Patterns – Visitor Pattern Principles and Usage Example Analysis
  • JavaScript Design Patterns – Template Method Pattern Principles and Usage Example Analysis
  • JavaScript Design Patterns – Observer Pattern Principles and Usage Examples
  • JavaScript Design Patterns – State Pattern Principles and Usage Examples
  • JavaScript and JQuery Framework Basics Tutorial

<<:  Detailed explanation of the principle and usage of MySQL stored procedures

>>:  Use prometheus to count the remaining available percentage of MySQL auto-increment primary keys

Recommend

Basic usage and examples of yum (recommended)

yum command Yum (full name Yellow dog Updater, Mo...

How to export and import .sql files under Linux command

This article describes how to export and import ....

Tutorial diagram of using Jenkins for automated deployment under Windows

Today we will talk about how to use Jenkins+power...

Common symbols in Unicode

Unicode is a character encoding scheme developed ...

Tips for making web table frames

<br />Tips for making web table frames. ----...

WeChat applet custom tabBar step record

Table of contents 1. Introduction 2. Customize ta...

Introduction to the functions and usage of value and name attributes in Html

1. The value used in the button refers to the text...

Introduction to query commands for MySQL stored procedures

As shown below: select name from mysql.proc where...

MySQL view principles and basic operation examples

This article uses examples to illustrate the prin...

Use scripts to package and upload Docker images with one click

The author has been working on a micro-frontend p...

Detailed explanation of Linux command file overwrite and file append

1. The difference between the command > and &g...