JavaScript has a bad reputation on the Internet, but it is hard for you to find another language that is so dynamic, so widely used, and so rooted in our lives. Its low learning threshold makes many people refer to it as a pre-school scripting language. Another thing that makes people laugh at is the concept of Dynamic Language, which uses a high standard of static data. In fact, you and JavaScript both have taken the wrong stance, and now, you make JavaSript very angry. There are five reasons to explain that your JavaScript technology is poor.
1. You are not using a namespace.
Do you still remember that the university teacher told you not to use global variables in your homework? The use of global variables in JavaScript is no exception. Web pages become messy and messy, and scripts and script libraries are everywhere from every corner of the Internet. If you name a variable loader (), you are looking for trouble. JavaScript will not remind you If you reload a function unconsciously. You still call it a preschool education programming language, remember? What I want to say is that you need to know what will happen after doing this.
- function derp() { alert(“one”); }
- function derp() { alert(“two”); }
- derp();
"Two", the answer is "two ". This is not always the case. It may also be "one ". Therefore, it is easy to put all your code in your namespace. The following is a simple way to define your own namespace.
- var foospace={};
- foospace.derp=function() { alert(“one”); }
- function derp() { alert(“two”); }
- foospace.derp();