Skip to content

Instantly share code, notes, and snippets.

@rkhaslarov
Created March 5, 2022 11:08
Show Gist options
  • Save rkhaslarov/cf35275abee481ac7d8d4d47b16f1c12 to your computer and use it in GitHub Desktop.
Save rkhaslarov/cf35275abee481ac7d8d4d47b16f1c12 to your computer and use it in GitHub Desktop.
const TRUCK = 1;
function getCarByType(type) {
if (type === TRUCK) {
return { name: 'Super Truck' }; // imagine that it's a truck object
}
return { name: 'Usual Car' };
}
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' };
}
const ProcessStatuses = {
STARTED: 1,
IN_PROGRESS: 2,
FINISHED: 3
}
const ProcessStatuses = Object.freeze({
STARTED: 1,
IN_PROGRESS: 2,
FINISHED: 3
});
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