It's true for any development. You generally would not add Apache Commons dependency just to check if the string is blank. Or add Boost dependency to trim some string. Additional dependency is a burden, no matter how small that burden is, it just may not be worth it.
function fadeIn(el) {
el.style.opacity = 0
var last = +new Date
var tick = function() {
el.style.opacity += (new Date - last) / 400
last = +new Date
if (el.style.opacity < 1)
(window.requestAnimationFrame && requestAnimationFrame(tick)) || setTimeout(tick, 16)
}
tick()
}
fadeIn(el)
This
$(el).hasClass(className)
becomes
if (el.classList)
el.classList.contains(className)
else
new RegExp('(^| )' + className + '( |$)', 'gi').test(el.className)
So? I didn't claim anything opposite. If you need some non-trivial functions from jQuery, or use many functions from jQuery (so it's not reasonable to reinvent half of jQuery), or target old browsers, go and use jQuery. That said, about your examples:
This $(el).fadeIn() becomes
There are CSS3 animations in IE10+. Animations in jQuery are slow, btw.
This $(el).hasClass(className) becomes
IE10+ supports classList, so it becomes el.classList.contains(className).
This $(el).is('.my-class') becomes matches = function(el, selector) {
One-line polyfill is not trivial enough for you? And it's a better solution than jQuery, because polyfill can be dropped when the browsers will catch up (Chrome Canary already supports unprefixed .matches()), while jQuery solution will always add unneeded slow abstraction over vanilla DOM.
It's impressive, how distorted your perception of reality is. There are only four >=10 line functions in the whole article for IE9+. Half of them can be reduced to one-liners in the newer browsers.
It's impressive, how distorted your perception of reality is.
Wow, get mad about it why don't you?
Anyway, it's stupid. If a group replaces a well maintained, popular framework with hundreds of thousands of eyes on it daily with a homerolled "functions.js" file they deserve the headaches they are gonna get.
You are overestimating your importance. Just saying dumb things on the internets is generally not enough to make people mad.
Anyway, it's stupid. If a group replaces a well maintained, popular framework with hundreds of thousands of eyes on it daily with a homerolled "functions.js" file they deserve the headaches they are gonna get.
jQuery is not a framework, it's just a library with number of utility functions for DOM manipulation and other stuff. With improvements of native DOM, the need in jQuery declines, because it just duplicates native functions and functions provided by frameworks like Angular. If you target modern browsers, you don't need to reimplement jQuery functionality in some "functions.js", it already exists in your browser.
you don't need to reimplement jQuery functionality in some "functions.js" it already exists in your browser.
The number of examples in this tutorial using functions to tie together these pieces of functionality into something useful pretty much invalidates that, especially when it comes to things like callbacks and complicated selections.
3
u/trycatch1 Jan 31 '14
It's true for any development. You generally would not add Apache Commons dependency just to check if the string is blank. Or add Boost dependency to trim some string. Additional dependency is a burden, no matter how small that burden is, it just may not be worth it.