I have been working on JS for a year since I started to be exposed to this thing, and I always feel a little unspeakable depression in my heart. People often say this in forums. So where is the pain? I always feel that I don’t learn in depth, and I can do some simple things but I can’t do them easily. Can you explain this kind of suffering more specifically? How can you be specific if you say "unspeakable depression"?
What is the hidden secret? If you can't say it out, you can't be specific, and if you can't put the problem into practice, you can't be solved. This is the hidden secret! I think this is the "dilemma" for beginners. The reason why "I think" is used just to cater to the word "experience" in the title of this article. I'm very happy if it can help everyone.
Let’s get back to the point. After thinking and thinking, I have summarized the following "unspeakable hidden secrets" for beginners. Let’s see if you have mentioned our hearts. Haha.
1. Use systematic knowledge to define the problem
When we learn, we often find that we can use different methods to achieve the same problem. For example, to bind a click event to an element, you can use <a href="#" onClick="f1()"></a> on the HTML element, which we would initially think is how to bind events.
When we see the second time we can pass a function to an event to bind: =f1; then we will think that there is more than one way to bind events.
When we see the third time we use addachEvent("onclick",f1) to bind events, you will definitely think that there may be more than these three methods to bind events. And there is no reason to do one thing three identical methods. There must be differences between them?
So what are the differences between them? How many ways are there to bind events? When you find that a method is incompatible in IE, you will ask why? Is it because my syntax is wrong? Still what happened. After one question after another you have to ask yourself: "Oh my God! When will I learn JavaScript well?!"
It may be difficult for you to learn JS well if this continues. In fact, I have to tell you that you are not far from learning to learn, but you don’t know how to go. What is the reason? The reason is that there is no systematic knowledge, the reason is that you have never read the "Authoritative Guide to JavaScript". It will tell you that there are four methods for binding events, and two are basic methods, all browsers support it, and there are two advanced methods, one is the W3C standard method and the other is the IE standard method, so you know why IE is incompatible with one of the advanced methods, right?
Now that things are concrete, when binding an event, you only need to consider these four methods, and you will not have so many doubts anymore. You will also feel that you understand the incident. You should understand other problems in the next step. You will also feel that you have finally made progress in JS. Of course, you will also feel that you have come out of a dilemma.
2. Must understand the history of JavaScript
Do you know the history of JS? Of course I understand that he was not originally called JavaScript, and he was not implemented in IE at the beginning. Yes, it's very good, but this is not the most important thing. You won't become a master even if you know this. You must know more in detail, and mainly understand the history of functional evolution.
Just like above, why are there so many ways to bind events? Why are there so many ways to get an element? After all, it is [] a little more formal? Or is it more formal to getElementsByTagName('a')? Which one is better compatibility? How many other methods are there?
You should know that one problem is enough to have a headache. You have no way to start with ten problems. You will doubt yourself if you have a hundred problems. One Thousand Questions Finally, I returned to the question "Oh my God! When will I learn JavaScript well"? Haha, this is often the case. The solution is to concretely understand how many methods are there and why. These questions will definitely have answers, because JS is not something left by aliens, it is created by humans, and that person's thinking is also limited, isn't it?
When you know [] is a legacy document method, and there are 5 legacy methods in total. When anchors[], applets[], forms[], images[], links[], some problems disappear. When you still know that the DOM standard retains them, you also know that all browsers support them, you also know that they are the so-called "level 0 DOM" and you will get out of a "dilemma".
3. JS has a crisscrossing knowledge structure
The knowledge structure of JS is interleaved horizontally and vertically, which increases the difficulty of understanding it, and a clear understanding of this must be achieved. Let’s explain the “crossing” below.
General knowledge has a horizontal nature. For example, from a large aspect, JS is divided into core part and client part. This is horizontal. The core parts are further divided into lexical structures, data types and values, variables, expressions and operators, statements, objects and arrays, functions, classes, modules and namespaces, and regular expressions. This is also horizontal.
The client part can be divided into BOM, DOM, events, styles, forms, etc. These are also horizontal knowledge structures.
A technology rarely uses time as a structure, but because the development of the browser is dynamic, browsers in different periods have different degrees of implementation of JS. However, at different times, the web pages written by the browser at that time cannot be considered because of the development of technology. Moreover, it is impossible to rewrite all websites with the development of technology. Therefore, JS must develop and upgrade, and also retain forward support. So even if there is a better method, the previous method must be retained. There are many legacy JS attributes and methods, such as the "level 0 DOM" being retained in the new W3CDOM, to a certain extent, it is vertical.
When you have a clear understanding of the knowledge structure, one advantage is that when I want to solve a problem, I can know which piece of knowledge I want to use. For example, if you want to get the position of an element in the document, you will know that the attributes of the element in the DOM are used. To get the position of the mouse pointer, you must use the attributes of the event object. To obtain a reference to an element, you can use the legacy DOM or the W3C standard DOM method. This is a good thing.
In fact, the core of the above problem is systematization and concretization, which is something I think is very important in the learning process. This has indeed solved a lot of doubts for me.
To get out of the dilemma of beginners, we need systematic knowledge and concrete ideas. Thank you for taking the time to read this article hope it will be helpful to you. If you want to discuss more questions, please add my QQ: 303551651.