Home > Web Front-end > JS Tutorial > Several rules to pay attention to when writing JS code_Basic knowledge

Several rules to pay attention to when writing JS code_Basic knowledge

WBOY
Release: 2016-05-16 18:20:03
Original
888 people have browsed it

1. Don't use document.write() a lot

2. Check the client's ability to support the object (progressive) Instead of checking its client, test the object you want to use.

3. Access content in existing HTML instead of adding HTML through Js (separation of behavior layer and structure layer)

4. Do not use proprietary DOM objects (such as IE's document.all )

5. Put the script into a .js file instead of appearing everywhere in HTML.

6. Make improvements to a website that works well and doesn't require client-side programming, rather than adding scripts first and then adding non-script alternatives.

7. Keep the code independent and do not use global variables that may conflict with other scripts. (Object literal available)

8. Comment the code function, because you may be the one maintaining the code in the future.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template