7 ms·
It's like seeing this in everyone's JavaScript $('.some_selector').action(); ... $('.some_selector').anotherAction();
by emehrkay 11y ago
It's like seeing this in everyone's JavaScript
$('.some_selector').action();
...
$('.some_selector').anotherAction();
- Cshelton 11y agoI excluded some candidates right off the bat for this...grabbing the same element 4 times in one function....no I am not hiring you...
- Cthulhu_ 11y agoIsn't there a decent caching system behind that? OTOH, .action() could change the whole dom so that .some_selector matches something else or nothing at all, so I guess jquery couldn't make that assumption / optimization without knowing what .action() does, or without doing a deep analysis of what DOM elements .action() altered and whether the selector on the next line is affected.
- maxxxxx 11y agoI have been in discussion where somebody would argue that using a variable for $('.some_selector') would be inefficient because it's more lines of code.
- TheHegemon 11y agoThank you! That is one of my greatest pet peeves. Or needless selectors like $('div.some-div input.some-input') where the classes are never used on anything other than divs/inputs. Another thing I've seen: $('#someId #childId').