9 ms·
Rather than using a library with a bunch of utility functions that you may or may not need, using individual utility functions indeed does seem like a better id
by Touche 9y ago
Rather than using a library with a bunch of utility functions that you may or may not need, using individual utility functions indeed does seem like a better idea.
For example, I don't support browsers without classList, so I don't need your regexp stuff. Maybe you do, but my code shouldn't be larger because of that.
- jonursenbach 9y agoProblem now is that you get to write, test and maintain all this instead of using something that has a whole community backing it.
- hw 9y agoMost of these utility functions are fairly straightforward and will rarely require any changes or maintenance. Testing should therefore be straightforward as well. Having the whole community back something doesn't mean it's bug-free, and sometimes it makes it harder when their release cycle isn't as frequent as you'd like it to be. Having said that, it's all about tradeoffs. Whether your project needs something as big as <insert JS framework or lib here> or if you can live with just needing a few utility functions, you make those choices, doesn't mean one is better than the other as it all depends on context and situation. jQuery has become the defacto must-use library for javascript now which IMO is unfortunate, as a lot of sites and apps include it when they barely use most of what jQuery offers. I'm guessing most use jQuery for only a few things - Ajax, DOM querying, and events. I hope that sometime in the future jQuery would be more modular.
- Touche 9y agoIf you search for classList on npm you get a half dozen results. I disagree with your assessment here.
- aurbano 9y agoDead code elimination (i.e. UglifyJS) should do away with most unused code from a library - so with a proper build system this shouldn't be a big concern...
- madeofpalk 9y agoI don't think you'll find UglifyJS's dead code elimination to do the type of tree shaking that'll remove jQuery's unused functions.
- kitsunesoba 9y agoWhat if one wants to keep things simple with a minimal/nonexistent build system? I haven’t done serious web work in ages but if I did I’m quite sure I’d find all of today’s “required” build tools quite frustrating.
- jonknee 9y agoAnd yet by "keeping it simple" you have to re-write and maintain a bunch of utility functions that are solved problems.
- megous 9y agoIf it's for some gain, then why not. It's a trade off decision.
- rhizome 9y agoIf they're solved problems, what difference does it make what form and package they arrive in?
- Touche 9y agoYou say that as those jQuery is the only place you can get a addClass function without writing it yourself. It isn't.
- jonknee 9y agoNot at all, OP said "if one wants to keep things simple with a minimal/nonexistent build system" which would exclude the easiest ways to get one-off utility functions.
- no_wizard 9y ago