3 ms·
I thought I was smart... BEFORE function vis(el, on) { if (el) { on ? remClass(el, 'nosee') : addClass(el, 'nosee') } } AFTER function vis(el, on) { if (el)
by AltruisticGap 8y ago
I thought I was smart...
BEFORE
function vis(el, on) { if (el) { on ? remClass(el, 'nosee') : addClass(el, 'nosee') } }
AFTER
function vis(el, on) { if (el) { window[on ? 'remClass' : 'addClass'](el, 'nosee') } }
...sadly we have to add window when using the square brackets so it's not much shorter. Oh well.
- Arkanosis 8y agoWhy not: function vis(el, on) { if (el) { (on ? remClass : addClass)(el, 'nosee') } } ?
- AltruisticGap 8y agoAhh thanks! I forgot about that. I'm guessing I didn't think about it because I'm used to the following pattern ,which is actually useful from time to time in my projects. And typically it happens in an object/class: this[expr ? 'method1' : 'method2'](args) So I have to add "this" as the methods are not global. Now if I overlooked something again I'm definitely getting rusty :)
- dang 8y agoYes, that's better, especially since we do it elsewhere. Thanks!