ES6 code standard writing is organized, the use of quotation marks, single quotation mark ' ' takes precedence (if it is not a nested quotation mark, do not use double quotation marks), the use of spaces: (after the keyword symbol typesetting function assignment symbol =), etc. .
Normal situation: console.log('hello there') Double quotation marks Code: $("
")
a Function brackets: function hello (name) {} Look at (parameters) The "left and right outside the brackets" ( ) have spaces, and the "left and right name inside the brackets" have no spaces
b A space is required after the keyword: if (condition) { ... } A space is required between if and ()
c Assignment symbol = Spaces are required on both sides: var x = 2 Assignment symbol = Spaces are required on both sides
d Spaces are required on both sides of the string splicing symbol: var message = 'hello, ' name '!' The number between constants and variables, spaces are required on the left and right sides
e Comma, do not leave it in front Space, leave a space after: var list = [1, 2, 3, 4] function greet (name, options) { ... } Do not leave a space before the comma
If () {} else {}: } else { To be in one line
} else {
//
}
4. Do not write unused variables. If a variable is defined and has not been used in operations, it should not be defined. this variable.
5. Use === instead of ==. When comparing equal, == will take one more step of data conversion, but when in the if (a!=undefiend) {} condition, a!=undefiend simultaneously There are dual meanings of a!==undefiend and a!==null (null == undefined)
? 'localhost'
: 'www .api.com'
Continuous writing:var leds = stage.selectAll('.led') .data(data) . enter().append('svg:svg')
.class('led', true) .attr('width', (radius margin) * 2)
.append('svg: g')
.attr('transform', 'translate(' (radius margin) ',' (radius margin) ')')
.call(tron.led);
8 , Comment question: There should be a blank line with the previous line. In addition, there should be no large blank lines for no reason. Empty line
/ / Here are the comments
Multi-line comments
: (
This can also be used for copyright information comments)
/**
* make() returns a new element * based on the passed in tag name * * @param
9. Problem at the beginning: Do not start with ( [ ` , but add the ; sign
# before the beginning.
## ;(function () {window.alert('ok')}())
;[1, 2, 3].forEach(bar)
var errorMessage = 'This is a super long error that '
'was thrown because of Batman.'
'When you stop to think about '
'how Batman had anything to do '
'with this, you would get nowhere '
'fast.';
Use the join method for loops or multi-line strings To construct
function inbox(messages) {
items = [];
for(i = 0; i < length; i ) {
Items[i] = messages[i].message;
}
return'
}
a When naming private properties, add an underscore_ in front of it, such as: In the constructor, this._firstName = 'Panda'; var _firstName = firstName;
b Add a $ to the name of the jq variable to distinguish the js variable
Related articles:
Introduction and export of commonJS and es6 specifications
Daily js development specifications
Related videos:
Javascript - ES6 practical video course-free online video tutorial
The above is the detailed content of Practical, a compilation of ES6 code specification writing methods in js development. For more information, please follow other related articles on the PHP Chinese website!