5 ms·
I do all my personal mvps now in vanilla JS, I can get ideas fleshed out faster without fumbling over frameworks.
by droobles 7y ago
I do all my personal mvps now in vanilla JS, I can get ideas fleshed out faster without fumbling over frameworks.
- mschuster91 7y agoOut of random interest, not even jQuery? I find it immensely tedious to write out vanilla js compared to all the shortcuts that $ provides...
- xingyzt 7y agoQuerySelectorAll is widely supported and you can make your own shorthand for it. function $(query) { const result = document.querySelectorAll(query) if ( result ) { if ( result.length > 1 ) { return result } else { return result[0] } } }
- bfred_it 7y agoI hope you don't use that since it randomly returns either an element or a list of elements, so you'd have to also add an if/else every time you use it. This is my go-to: const $ = document.querySelector.bind(document); const $$ = document.querySelectorAll.bind(document); Tip: browser consoles already have these shortcuts, except $$ returns an actual array there instead of a NodeList.
- mellow2020 7y agoKnowing that jQuery ends up calling those very same functions, only often after jumping through a bunch of hoops, doesnt make me consider it a shortcut. Between auto-complete and copy and paste, I prefer slightly more "work" up front, and then zero needless work at runtime, than a bit of "magic" that ends up doing needless work every single time it is run. But I have to admit, I don't care about compatibility beyond Firefox on the desktop, if I wrote stuff for a company on a deadline, or if I worked with other people on something, I would mind jQuery very little or not at all. But for my own stuff I make to spark joy, where I get to decide all of it, I want it as vanilla as I can get it.
- no_wizard 7y ago> copy and paste Bravo for admitting it. I have to say I've usually run into trouble working with copy and paste coders though. How do you make sure what you're doing this with is something you understand? I never understood this one.
- mellow2020 7y agoI just meant copying and pasting long function and variable names out of my own code elsewhere, should autocomplete somehow not apply.
- droobles 7y agoNot even jQuery. The dom selector API is cohesive enough these days for my use.
- CSSer 7y agoI'm not totally anti-jquery, but it helps to stay lightweight. If convenience is what you're after, you can always just bind querySelector and querySelectorAll to the document and assign each to a variable like this: https://dev.to/mrahmadawais/use-instead-of-document-queryselector-all-in-javascript-without-jquery-3ef1 https://dev.to/mrahmadawais/use-instead-of-document-querysel...
- throwaway55554 7y agoIf they do this regularly, they surely have a personal toolbox of js code they can draw from that handle most everything jQuery would provide.
- droobles 7y agoYep, especially for handling events (which I try to use sparingly :)). That was one thing jQuery had a great out of the box API for.
- hombre_fatal 7y agoThis line of reasoning only made sense in the old days. For example, $.ajax() is strictly worse than the native window.fetch() -> Promise we have today. I could see using jQuery in 2020 if your poor soul still has to support ancient browsers, but beyond that I suspect people only latch on to jQuery out of habit.
- mschuster91 7y ago> I could see using jQuery in 2020 if your poor soul still has to support ancient browsers IE 11 at work for some customer projects. It's dreadful. No support for anything decent, but at least the debugger is better than the "nothing" you had with IE6...
- woutr_be 7y agoThe main advantage of jQuery these days is all the plugins it provides, most (if not all) things you need on a website exist in jQuery. And I also found it really has messed up search results, search for anything javascript related, and almost all answers you find on StackOverflow are people suggesting to use jQuery. (Even when the author didn't ask for it) The other day I was looking for a simple markdown editor, and it took me a while to find a decent vanilla one. (Ended up using https://simplemde.com https://simplemde.com)