Clean Code – functions should do one thing
by riddla
JavaScript
/*
# Smells and Heuristics
## G28: Encapsulate Conditionals
Extract boolean logic to a function that explains the intent of a conditional
*/
var Roadrunner = function() {
this.isFleeing = false;
this.isInAsavePlace = true;
this.hasEscaped = function() {
return !this.isFleeing && this.isInAsavePlace;
}
};
var roadRunner = new Roadrunner();
if (roadRunner.hasEscaped()) {
console.log('Meep, Meep');
}