Odd Dance JS Notes--2nd lesson--code style

Source: Internet
Author: User

Note:

1. Learn the video address

2.ppt Address

3. Personal Impressions:

Is my great master recommended me to see the shadow of the month big video, I feel for this small white, really is over and over again refresh knowledge. I feel like the Moon shadow greatly this big guy's train of thought, my contact after really benefited.

So I summed up not only my own notes, but also want to be a true front-end "engineer" front-end er.

Really cherish this knowledge is refreshed feeling-the more study, the more feel their ignorance, mutual encouragement.

Directory

1. The meaning of code style existence

2. What is the code style?

3. What code style to follow

4. How to learn code style

5. Some special code styles: Iife, Dependency injection, module, strict mode

6. Code Style Check Tool

7. After-school assignments

Body

1. The meaning of code style existence

(The reason why language, not assembly or 010101, is to allow people to understand)

2. What is the code style?

format of the code (including indents, braces, semicolons, line breaks, blank lines, spaces)

In broad sense:

directory structure & file name

Variable naming

Document specification

3. what style of code to follow:

(It is important to have a team or project that is consistent and adheres to the same Code style)

Common specifications:

1. Two spaces as indentation (not necessarily required)

2. String in single quotation marks ( because HTML attribute names are double quotes )

3. Do not use the variable (GET)

4. Do not write a semicolon (this is your preference)

5. Do not start with (['] (Affect iife immediate execution function)

6. Keywords after the space: if () {...} (not necessarily required)

7. Space between function name and parameter: Functions name (...) {...} (not necessarily required)

8. Use = = = instead of = =, in addition to judging an object ==null (because it is a weak type, two equals may force an implicit type conversion)

9. Error handling in Nodejs err to process parameters

10. Write the prefix window for the global object, except Window.document and window.navigator can omit window

4. How to learn code style

The best way to learn the code style is to read the code

You can see the most common styles on GitHub (

For example, many items have semicolons,

Many left curly braces are written on the same line,

/** General comments or functions in front of

* this

* Style

*/,

other lines of comment //,

5. Some special JS" style "

iife(immediately-invoked Function Expression) Iife and Dependency injection

Some anonymous functions have parameters.

Some of the anonymous function parameters are empty

Parameter is empty:

Created a function-level scope to make sure that the variable I declare between this function is accessible only within the body of the functions, and avoids anyone accessing my variables externally.

parameters are: ( Dependency Injection Specification )

You can put the global,jquery,document as parameters, put my about in this module to use something explicit through the parameters exposed, Do not use anything outside of the scope

AMD Module Management Specification

For example , the Require.js Module management tool

SYSTEMJS Module Management Specification

Strict mode (use strict)

6. Code style Check tool

Eslint/jslint/jshint

Standard

Semistandard

(the latter two are based on ESLint)

(editor Sublime , etc. have plugins for these tools)

(git can use a module to check the code before committing the code)

7. homework after class

find a few different projects on GitHub, watch their code styles, write a short essay, introduce them and talk about what style of code you like, why?

Imitation NPM module, write a simple JavaScript function Module yourself, and submit it to GitHub with your favorite style .

The Code style Check tool that you write to the module application, you can choose ESLint, Standard, or other code-checking tools.

Odd Dance JS Notes--2nd lesson--code style

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.