Answer the question
In order to leave comments, you need to log in
Why are static methods in js bad?
I am writing the front in Angular. There was a task to store filter data in localStore, for this I created a class with static methods:
export class FilterStorageUtil {
private static storage = window.localStorage;
private static prefix = 'StorageFilter-';
public static setFilter<T extends object>(filter: T, key = location.pathname) {
const itemKey = this.prefix + key;
this.storage.setItem(itemKey, JSON.stringify(filter));
return true;
}
public static getFilter(key = location.pathname) {
const itemKey = this.prefix + key;
const jsonFilter = this.storage.getItem(itemKey);
try {
return JSON.parse(jsonFilter);
} catch (e) {
return null;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question