What is MVC?

MVC represents three modules, namely M, V and C, and each module can be written as three objects. The M-Model is responsible for manipulating all the data, the V-View is responsible for all the UI, and the C-Controller is responsible for all the other parts except for the first two. MVC is not very well defined, it’s a design pattern that optimizes the structure of your code. Fully understanding MVC is complicated. It is similar to the idea of standardization, that is, repetitive things and concepts, through the formulation, release and implementation of standards to achieve unity, in order to obtain the best order and the best benefits.

1. What does MVC do?

Examples of pseudocode are given below:

let M = {} , V = {} , V. ender = (M) => {display(M)} // View is responsible for all THE UI interface rendering Const M = {data: {data}, Method: const M = {data: {data}, Method: Const v = {el:null, HTML: 'code',  init(container){ v.el = $(container) }, Render ()} const c = {init(container){} events:{events} add(){} minus(){} update(){} get(){} autoBindEvents(){logic}}Copy the code

2. What apis does EventBus have? What is it used for

Example of API pseudocode commonly used in EventBus:

import $ from 'jquery' class EventBus { constructor() { this._eventBus = $(window) } on(eventName, Fn) {return this._eventbus. on(eventName, fn)} // Listens for registration events and executes the specified method (and insertion point). Trigger (eventName, data) {return this._eventbus. trigger(eventName, data)} // Trigger a specific event and execute the corresponding implementation method queue. Off (eventName, fn) {return this._eventbus. off(eventName, fn)} // Cancel the registration event. } export default EventBusCopy the code

3. What does table driver programming do

Table Driven Approach (Table Driven Approach), simply speaking, refers to the method of looking up tables to obtain values. When the value is small, we can use logical statements (if or case) to obtain the value, but as the value increases, the logical statements become longer and longer, and the advantage of table driven method becomes apparent. One of the problems that must be solved when using table-driven methods is how to look up tables. The common table lookup methods are

  • Direct query
  • Indexing query
  • Segmented query

Direct query, refers to the need to go around the circle, with the way of the subscript can smoothly get the data, the following example code only demonstrates the direct query method:

Const week = {" Sunday ", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",} let day = week[day]Copy the code

A single statement can replace a long if-else statement. The central premise of data-driven programming is that humans are better at processing data than program logic.


4. How do I understand modularity

As currently understood, a module is a set of methods that implement a specific function. Simply put the different functions (and the variables that record the state) together, and it can be considered a module. The influence between codes is simplified through export/import operations.

Let string = "string" import default string import $from 'string' // importCopy the code