Created
March 5, 2022 11:08
-
-
Save rkhaslarov/cf35275abee481ac7d8d4d47b16f1c12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const TRUCK = 1; | |
function getCarByType(type) { | |
if (type === TRUCK) { | |
return { name: 'Super Truck' }; // imagine that it's a truck object | |
} | |
return { name: 'Usual Car' }; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const TRUCK = 1; | |
const SEDAN = 2; | |
function getCarByType(type) { | |
if (type === TRUCK) { | |
return { name: 'Super Truck' }; // imagine that it's a truck object | |
} | |
if (type === SEDAN) { | |
return { name: 'Starry Sedan' }; // imagine that it's a sedan object | |
} | |
return { name: 'Usual Car' }; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ProcessStatuses = { | |
STARTED: 1, | |
IN_PROGRESS: 2, | |
FINISHED: 3 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ProcessStatuses = Object.freeze({ | |
STARTED: 1, | |
IN_PROGRESS: 2, | |
FINISHED: 3 | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProcessStatuses { | |
static STARTED = new ProcessStatuses('STARTED', 1); | |
static IN_PROGRESS = new ProcessStatuses('IN_PROGRESS', 2); | |
static FINISHED = new ProcessStatuses('FINISHED', 3); | |
constructor(key, value) { | |
this.key = key; | |
this.value = value; | |
// here you can include more different properties | |
Object.freeze(this); | |
} | |
// toString is just an example of some custom logic that can be implemented here | |
toString() { | |
return `[${this.key}]${this.value}`; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment