August 15, 2020 ( last updated : August 14, 2020 )
javascript-convention
https://github.com/gmm117/gmm117.github.io
javascript-convention
const onClick = () => {};
const onKeyDown = () => {};// bad
function MyFunction() {...}
// good
function myFunction() {...}// bad
function whereIsCamera() { ... }
// good
function findCamera() { ... }
function getFoo() { ... } // getter
function setBar() { ... } // setter
function hasCoo() { ... } // booleans// good
class User {
constructor(options) {
this.name = options.name;
}
}
const good = new User({
name: 'yup',
});탭을 이용한 들여쓰기는 하지 않지 않고 공백 문자 2개를 사용한다.
// bad
const len = items.length;
const itemsCopy = [];
let i;
for (i = 0; i < len; i++) {
itemsCopy[i] = items[i];
}
// good
const itemsCopy = [...items];ES5의 환경에서는 Array.prototype.slice를 사용한다. (ES5)
// Good
itemsCopy = items.slice();// Bad - 개행
const obj = {foo: 'a', bar: 'b'}
// Good
const obj = {foo: 'a'};
// Good
const obj = {
foo: 'a'
};// Bad - 개행
const obj = {foo: 'a', bar: 'b'}
// Good
const obj = {foo: 'a'};
// Good
const obj = {
foo: 'a'
};// Bad
const atom = {
value: 1,
addValue: function(value) {
return atom.value + value;
}
};
// Good
const atom = {
value: 1,
addValue(value) {
return atom.value + value;
}
};// Bad
class MyClass {
foo() {
//...
}
bar() {
//...
}
}
// Good
class MyClass {
foo() {
//...
}
bar() {
//...
}
}// Bad
var value;
if(typeof str==='string') {
value=(a+b);
}
// Good
var value;
if (typeof str === 'string') {
value = (a + b);
}// Bad - 괄호 안에 공백
if ( typeof str === 'string' )
// Bad - 괄호 안 공백
var arr = [ 1, 2, 3, 4 ];
// Good
if (typeof str === 'string') {
...
}
// Good
var arr = [1, 2, 3, 4];// Bad - 콤마 뒤 공백
var arr = [1,2,3,4];
// Good
var arr = [1, 2, 3, 4];// bad
const foo = {clark: 'kent'};
// good
const foo = { clark: 'kent' };// Bad
if (condition) {
function someFunction() {
}
} else {
function someFunction() {
}
}
// Good
var someFunction;
if (condition) {
someFunction = function() {
...
}
} else {
someFunction = function() {
...
}
}// Bad - 불필요하게 개행
var foo,
bar,
quux;
// Good - 선언만 하는 변수, 한 줄로 연결
var foo, bar, quux;// bad
let i, len, dragonball,
items = getItems(),
goSportsTeam = true;
// bad
let i;
const items = getItems();
let dragonball;
const goSportsTeam = true;
let len;
// good
const goSportsTeam = true;
const items = getItems();
let dragonball;
let i;
let length;https://ui.toast.com/fe-guide/ko_CODING-CONVENSION/
Originally published August 15, 2020
Latest update August 14, 2020
Related posts :