// bad
function q() {
// ...
}
// good
function query() {
// ...
}
// bad
const OBJEcttsssss = {};
const this_is_my_object = {};
function c() {}
// good
const thisIsMyObject = {};
function thisIsMyFunction() {}
// bad
function user(options) {
this.name = options.name;
}
const bad = new user({
name: 'nope',
});
// good
class User {
constructor(options) {
this.name = options.name;
}
}
const good = new User({
name: 'yup',
});
// bad
this.__firstName__ = 'Panda';
this.firstName_ = 'Panda';
this._firstName = 'Panda';
// good
this.firstName = 'Panda';
// bad
const opened = true;
const options = false;
// good
const isOpened = true;
const hasOptions = false;
// bad
const userData = () => {...};
this.account = () => {...};
// good
const getUserData = () => {...};
this.createAccount = () => {...};
// bad
const onClick = e => {...};
const click = e => {...};
this.keyPress = e => {...};
// good
const handleClick = e => {...};
const handleChange = e => {...};
this.handleKeyPress = e => {...};
При этом входящие пропсы для хендлеров стоит именовать с префиксом on
// bad
<Component handleClick={this.handleClick} />
$.CustomSuperPlugin({
handleClick: handleClick,
});
//good
<Component onClick={this.handleClick} />
$.CustomSuperPlugin({
onClick: handleClick,
});
// bad
var inputs = $('input');
//good
var $inputs = $('input');