4 ms·
> Are you absolutely certain that everything that jQuery does can now be done in a clear and concise way using plain Javascript? Can you give us some examples
by josephg 9y ago
> Are you absolutely certain that everything that jQuery does can now be done in a clear and concise way using plain Javascript?
Can you give us some examples of things that you're worried can't be written clearly using plain JS? Obviously everything you can do with jquery you can do without jquery. Its just a library.
> Can you have a sophisticated selector for Event Delegation without using jQuery but make the code concise and easy to read?
What do you mean by event delegation in this context?
> What about child selectors ("ul.thisClass > li.thatClass" > span.otherClass")
document.querySelector / querySelectorAll supports this. Its available in all browsers on all platforms if thats how you chose to make web apps: http://caniuse.com/#feat=queryselector http://caniuse.com/#feat=queryselector
- paulddraper 9y agoMake an HTTP request. Parse the JSON body if a 200, otherwise log an error.
- josephg 9y agoI haven't tested it but I think this should work: fetch(url) .then(res => res.status === 200 ? res.json() : Promise.reject(res)) .then(data => { ... })
- deathanatos 9y agoAnd the Fetch API, has, according to caniuse[1], 76% support. I don't know that I can disregard 1 out of every 4 users, hence, jQuery. For some things, like those mentioned by twhb, where support is >90%, sure, ditch the library and use the supported stuff. But I don't think all of jQuery is that well supported, yet, and/or has as decent an interface. [1]: https://caniuse.com/#search=fetch https://caniuse.com/#search=fetch
- josephg 9y agoI suppose. Or just use a polyfill for old browsers. It increases your code size a little, but at least the bloat is temporary. https://github.com/github/fetch https://github.com/github/fetch or https://www.npmjs.com/package/fetch-ie8 https://www.npmjs.com/package/fetch-ie8
- teniutza 9y agoPolyfills are a good option in some cases. I, personally, try to stay away from them as much as possible. Once you add a polyfill (e.g. fetch), you' soon realize that you need another one (e.g. Object.assign) and soon you will have a list of polyfills to take care of. The advantage of jQuery in this regard is that it has all these "polyfills" in one place. I believe that jQuery is not "modular" enough for today's web development environment. The "light" version is a step in the right direction but it's not enough. If one could configure the "modules" needed and download/load a single file/library, it would be tremendous.
- paulddraper 9y agoYep, Fetch API would be fantastic....if it was widely supported.
- padseeker 9y ago> Can you give us some examples of things that you're worried can't be written clearly using plain JS? Obviously everything you can do with jquery you can do without jquery. Its just a library. The not() selector for jquery is one. The closest() is another that I have used multiple times. > What do you mean by event delegation in this context? This is what event delegation looks like in jQuery; $("ul#listid").( "click", "li.classThatMatters", function() { //do something }); How would event delegation look when selecting a child element with a specific class? Event delegation from scratch in vanilla js is longer than this. I don't know much about query selectors. I'm going to read up on them. I suspect it handles most if not all the basic stuff jQuery does. However I suspect that are use cases that it might now.
- jayshua 9y agoIf I understood your event delegation example correctly, I would use event.target.matches inside the event handler. Not the greatest support at the moment though.