JavaScript design patterns (0)-is there a bird to learn design patterns?

  Usually before the start of any series, I will write a short notice to extract and summarize the practical significance of this series, so that beginners can decide whether to learn this part without looking at the specific content. The content of "FBI Warning" appears in many of my articles. So in this article I will first make a brief summary of what I have learned so far.

  The first reference book in this series is Zeng Tan-"JavaScript Design Patterns and Development Practice". Simply comment on this book and the author. I personally think that this book is very well written. It is basically something for people to see. The content is very qualified. There is no place to go around, and the examples are easy to understand. understand. But the author is more general. The content of the book is actually similar to that of my blog. There are in-depth thinking, but there are few rich practices. If you insist, I read the XXX design pattern and then I will come up with a copy of the design pattern. That's it, of course, my code level is a little bit lower, the real big guys seem to think the code is relatively low. The above is a personal point of view. On the true level, I am far from the author.

  Before I started writing this article, I have read the publisher-subscribe model. Almost half of the book is like this. Basically, I write articles after reading them, and then writing while reading. Sometimes I use some The more advanced knowledge points will basically be added later. Of course, there is no advanced knowledge about design patterns, as long as people with a certain front-end foundation can understand it.

  Before learning design patterns, I hope you can understand that design patterns are a summary rather than a pattern. For example, our most commonly used for loop, you can use the native for (...), you can also use forEach and other methods, since this method of traversal access is so common, so some people will come out for this operation Ways to define a high-end vocabulary to appear to be relatively high-end. Even if you have never heard of the "iterator pattern", this will not affect your use of for loops. The so-called design patterns are nothing more than "high-level terms" for frequently used operations.

  So what is the use of learning design patterns?

  1. Put a cup in the interview, a forEach, you call it an iterator, it sounds like

  2. Summarize and optimize the code written by yourself. Basically, the design patterns are old coders who have code experience. After reading the design patterns, you can compare which codes of your own can apply the design patterns to change your code. Be more sophisticated and clear.

  3. Learn (plagiarize) the general method of design patterns and improve your code level. If you were asked to write a deep copy by hand, how would you write it? I believe that few of you can write a "standard answer" version. The code level of most people is like this, let you write a XXX function or requirement, ok, can write. But the things written are often flawed. If you are asked to write a deep copy, I guess you will go directly to Baidu to copy and paste. why? Because you are afraid of writing mistakes, you are afraid of omissions, and you don’t even know how to write a lot. Therefore, learning design patterns and copying other people's "writing" can help you write "perfect code" more confidently.

 

  Having said so much, in the end I still want to say that learning design patterns is actually useless. Even after most people read it, the code level still stays at the previous level. This is because the design model itself is a summary. In the book, it is a summary of all design patterns. For you personally, it is for you. The summary of the code written before, to put it bluntly, is what you used to know. I will give you a name that you didn't know before. If you don't use it, you will forget it. Practice is the only way to remember the truth.

  Summarize the design pattern with a high-end analogy: the important thing is not that you know the publisher subscription model, but that you can come up with the operation of two-way data binding.

  

  

 

Guess you like

Origin blog.csdn.net/dkr380205984/article/details/108361428