I tend to do this in JS as well, but it was more of a habit I carried from Python, which does not have switch..case and the common way to replicate that behavior is to use objects (dicts).
I would put the cases in a closure instead of the function itself to save some memory (granted it's a tiny bit).
constgetEditorType=(()=>{constitsCodeEditor=()=>'It is a code editor';constitsIDE=()=>'It is an IDE';consteditors={atom:itsCodeEditor,sublime:itsCodeEditor,vscode:itsCodeEditor,webstorm:itsIDE,pycharm:itsIDE,default:()=>'unknown'};returntype=>(editors[type]||editors.default)();})();
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I tend to do this in JS as well, but it was more of a habit I carried from Python, which does not have
switch..case
and the common way to replicate that behavior is to use objects (dicts).I would put the cases in a closure instead of the function itself to save some memory (granted it's a tiny bit).