Front-end Specification JavaScript specification
Reference 1-javascript-style-guide
Javascript-style-guide Original
Note
[array] copy array using slice ()
var len = items.length,
itemsCopy = [],
i;
// bad
for (i = 0; i < len; i++) {
itemsCopy[i] = items[i];
}
// good
-
itemscopy = items slice
-
[array] use slice to convert an object of an array of classes to a group of
-
function trigger () {
-
var Span class= "PLN" > args = array Span class= "pun". prototype slice call arguments
-
//...
-
}
[string] use single quotation marks for strings ‘‘
this personal habit, with a single quotation mark less click shift
, too long string using stitching wrap
string is used join
instead of string connections to build strings, especially IE
var items,
messages,
length, i;
messages = [{
state: ‘success‘,
message: ‘This one worked.‘
},{
state: ‘success‘,
message: ‘This one worked as well.‘
},{
state: ‘error‘,
message: ‘This one did not work.‘
}];
length = messages.length;
// bad
function inbox(messages) {
items = ‘<ul>‘;
for (i = 0; i < length; i++) {
items += ‘<li>‘ + messages[i].message + ‘</li>‘;
}
return items + ‘</ul>‘;
}
// good
function inbox(messages) {
items = [];
for (i = 0; i < length; i++) {
items[i] = messages[i].message;
}
return ‘<ul><li>‘ + items.join(‘</li><li>‘) + ‘</li></ul>‘;
}
[Properties] when accessing a property using a variable, use the brackets
- [variable]1) Always use
var
declaring variables to avoid polluting the global namespace; 2) var
declare multiple variables with one and new lines, indent four spaces; 3)
From for notes (Wiz)
Front End Specification