This style guide is inspired from the john papa style guide.
Pro :
- Easy to :
- Test
- Read
- Reuse
- Maintain
// IS
isLoading, isActive, isLogged, isSet, isVisible, isFinished, isFound, isOpen
// HAS
hasError, hasLicense, hasCar
// CAN
canEvaluate, canEdit, canRead
numberOfUsers, numberOfCars, numberOfItems, numberOfMessages, numberOfTickets
cars.computeTotalPrice();
get/set, add/remove, create/destroy, start/stop, insert/delete, increment/decrement, old/new, begin/end, first/last, up/down, min/max, next/previous, old/new, open/close, show/hide, suspend/resume, etc.
Pro Named Function :
- Easy to :
- Test
- Reuse
// Avoid
myArray.filter((value) => {
return item > 0 ? true : false;
});
// Recommanded
// + Test separately isPositive function
// + Reuse isPositive
// + Easier to read myFunc(isPositive);
const isPositive = (value) => {
return item > 0 ? true : false;
};
myArray.filter(isPositive);