Five reasons why your JS technology is bad (1)

Source: Internet
Author: User

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.

 
 
  1. function derp() { alert(“one”); }  
  2. function derp() { alert(“two”); }  
  3. 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.

 
 
  1. var foospace={};  
  2. foospace.derp=function() { alert(“one”); }  
  3. function derp() { alert(“two”); }  
  4. foospace.derp();  


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.