In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what are the JavaScript development skills?" in the operation of actual cases, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Web pages that use a lot of javascript code load slowly, and excessive use of javascript makes the page ugly and procrastinating. Soon how to use javascript effectively has become a very hot topic.
1. Keep the code as concise as possible
Maybe all of you have heard the problem of code brevity for many times. As a developer, you may use it many times in your code development process, but don't forget this in js development.
Try to add comments and spaces to the development mode to keep the code readable
Please delete spaces and comments before publishing to the production environment, and abbreviate variables and method names as much as possible
Use third-party tools to help you compress javascript.
2. Modify prototypes after thinking about it.
Adding new attributes to the object prototype is a common cause of script errors.
YourObject.prototype.anotherFunction='Hello'
YourObject.prototype.anotherMethod=function () {...}
In the above code, all variables are affected because they all inherit from yourObject. Such use can lead to unexpected behavior. Therefore, it is recommended to delete similar changes after use.
YourObject.prototype.anotherFunction='Hello'
YourObject.prototype.anotherMethod=function () {… }
Test.anotherMethod ()
DeleteyourObject.prototype.anotherFunction='Hello'
DeleteyourObject.prototype.anotherMethod=function () {… }
3. DebugJavascript code
Even the best developers make mistakes. To minimize similar errors, run your code in your debugger to make sure you don't encounter any minor errors.
4. Avoid Eval
Your JS works well without the eval method. Eval allows access to the javascript compiler. If a string is passed to eval as an argument, its result can be executed.
This can greatly degrade the performance of the code. Try to avoid using eval in a production environment.
5. Minimize DOM access
DOM is the most complex API, which slows down code execution. Sometimes the Web page may not be loaded or the load may be incomplete. It is best to avoid DOM.
6. Learn javascript before using the javascript class library
The Internet is full of javascript class libraries, and many programmers often use js class libraries without understanding the negative effects. It is strongly recommended that you learn basic JS code before using third-party libraries, otherwise, you will be prepared for bad luck.
7. Do not use "SetTimeOut" and "Setinterval" methods as alternatives to "Eval"
SetTimeOut ("document.getID ('value')", 3000)
In the above code, document.getID ('value') is treated as a string in the setTimeOut method. This is similar to the eval method, where a string is executed in each code execution, which degrades performance, so it is recommended that you pass a method in these methods.
SetTimeOut (yourFunction,3000)
[] is better than newArray ();
A common mistake is to use an object when an array is needed or when it is time to use an array. But the principle of use is simple:
"when the attribute name is a small consecutive integer, you should use an array. Otherwise, use an object"-author of DouglasCrockford,_JavaScript:GoodParts.
Recommendations:
Vara= ['1A', last minute, '2B']
Avoid:
Vara=newArray ()
A [0] = "1A"
A [1] = "2B"
9. Try not to use var many times
Programmers are used to using the var keyword when initializing each variable. Instead, it is recommended that you use commas to avoid extra keywords and reduce the size of the code. As follows:
VarvariableOne='string1'
VariableTwo='string2'
VariableThree='string3'
Do not ignore the semicolon ";"
This is often one of the reasons why people spend hours on debug.
This is the end of "what are the JavaScript development skills"? thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.