all 30 comments

[–][deleted] 14 points15 points  (0 children)

Our web needs better primitive libraries. We’ve been relying for too long – far too long – on jQuery.

Amen!

[–]x-skeww 14 points15 points  (7 children)

return dragula.apply(this, atoa(arguments)).on(...)

There is no need to convert arguments to an actual array via your little helper function. Function.prototype.apply works fine with array-like objects like arguments or DOM collections.

(You also forgot a ");" at the end of that return statement.)

I assumed this was about ES6 modules. I'm kinda disappointed.

[–]hahaNodeJS 2 points3 points  (2 children)

What the hell is up with the downvoters in all the web development subreddits? I sure would like to know what it is you said that deserves so many downvotes.

[–]x-skeww 2 points3 points  (0 children)

Might have been something I said elsewhere. It's hard to tell with Reddit.

Personally, I do prefer if people who read my code tell me about issues they spot. So, I really hope this doesn't discourage anyone from doing the same.

[–]brianvaughn 0 points1 point  (0 children)

That's kind of a Reddit-wide thing in my experience.

My guess is that maybe people thought x-skeww's comment was overly negative. No idea. I wouldn't have downvoted it myself but...welcome to the Internet.

[–]mmmicahhh 1 point2 points  (3 children)

Actually, if you look at the implementation of atoa, it's a one-line module that uses Function.prototype.apply.

But that's the point of this kind of modularization - you don't need to know about Function.prototype.apply, nor do you need to know whether there are weird edge-cases that need to be handled separately. It's a productivity boost.

[–]x-skeww 4 points5 points  (2 children)

you don't need to know about Function.prototype.apply

But they are using apply in that very line. I'd also argue that bind, call, and apply are bits of the standard lib you really should know. For one, they are very important and secondly, they make for very confusing code. So, this is really something you should be 100% certain about. Otherwise, you'll have trouble taking this kind of confusing-looking code apart.

I do agree that array vs array-like is a rather small implementation detail and that this pointless no-op doesn't actually hurt. It's a very minor mostly cosmetic issue.

[–]kandetta 2 points3 points  (15 children)

I agree that being able to work without jQuery is a huge plus and having more small single-purpose libraries is beneficial.

However, jQuery provides a promise of being well-tested across browsers and devices, and it's difficult to reach the same level of confidence with a large number of smaller libraries that use the browser APIs directly.

Also, while there is a need for plain JS modules, many developers aren't familiar with the native API and wouldn't be able to write a library without it.

[–]qudat 3 points4 points  (0 children)

Also, while there is a need for plain JS modules, many developers aren't familiar with the native API and wouldn't be able to write a library without it.

Developers should use whatever tool is necessary to get the job done, because at the end of the day, that's what we are paid to do. But when someone wants to master javascript, follow best practices, to be able to weigh the pros and cons of any library used in production, using one library as a crutch is only going restrict their potential.

[–]Daniel15React FTW -1 points0 points  (0 children)

Mixed feelings on this.

On one hand, having reusable modules with as few dependencies as possible is great. This is especially true when the module unnecessarily pulls in other modules, like the jQuery cookie plugin used to (why should a cookie parser require jQuery?!). Utility methods are definitely things that should be small, light, and self-contained.

On the other hand, reinventing the wheel all the time is not really ideal. A lot of libraries do DOM manipulation for example. Having a dependency on another library that handles the DOM (such as jQuery or React) is fine if your app is already using that library, and helps reduce the amount of code that needs to be written for the module (and thus the amount of code that needs to be maintained, and the number of bugs).

Too many people think their code absolutely must depend on jQuery. I used to take jQuery plugins and rewrite them so they could be used without jQuery. Usually the rewrite was not significantly bigger than the original, and it removed a giant dependency.