There are some confusions about front-end MVC:
Model: writing logic
Control registers and controls page node events, and implements page loading performance
So, in the development of large projects, should Model and Control be written in two separate .js files, or should they be implemented in one js, as long as the main v and M are separated?
If it is divided into control.js and model.js, will there be more page requests?
Please give me some help
Should Model and Controller be written in two separate .js files?
Yes! Separation is for a better encounter!Model is a collection of data operation methods, and Controller is responsible for calling Model methods and responding to View.
Will that increase page requests?The characteristic of large projects is that data flow is large and complex, and they are not separated. Data operation methods are interspersed in Controller (coupling), so There is no overall control over the operation of page data, and it is difficult to maintain and reuse. Separately, the Model only exposes methods. At this time, the Model can be regarded as a machine for producing data. When you call the corresponding methods and parameters in the Controller, it will return the corresponding data to you. The inside of the method is transparent to the Controller (decoupling). . Model is also easy to maintain and reuse, and even the requested URL can be separated and maintained separately.
@kraaas has already answered, no more to say.
When Model and Controller rise to concepts, what does it matter if they are divided or not? When the code is read by the machine, what does it matter whether it is divided or not? The problem is that the program is written for people to read, not for the machine to read. Therefore, it is convenient to read it as it is. Obviously separation is a kind of Better choice.