Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the JavaScript development skills suitable for novice Web front-ends?

2025-02-24 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 suitable for novice Web front-end". In the operation of actual cases, many people will encounter such a dilemma, so 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!

1. 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.

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 ()

Delete yourObject.prototype.anotherFunction = 'Hello'

Delete yourObject.prototype.anotherMethod = function () {… }

Here the editor has built a front-end learning and exchange QQ group: 132667127, I have sorted out the latest front-end materials and advanced development tutorials, if you want, you can join the group to learn and communicate together.

3. Debug Javascript 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. 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

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.

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 new Array ();

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 property name is a small consecutive integer, you should use an array. Otherwise, use an object"-Douglas Crockford, _ JavaScript: author of Good Parts.

Recommendations:

Var a = ['1A, 1A, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2

Avoid:

Var a = new Array ()

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:

Var variableOne = 'string 1'

VariableTwo = 'string 2'

VariableThree = 'string 3'

Do not ignore the semicolon ";"

This is often one of the reasons why people spend hours on debug.

This is the end of the content of "what are the JavaScript development skills suitable for novice Web front-end". 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report