Yes, you can re-implement jQuery in 10 lines of code... if you only support 0.1% of the functionality of jQuery. jQuery was a game changer for web client side development. Thousands of work hours have been spent on it. It had a specially important role of dealing with all the inconsistencies between browsers. If you don't use all the features, nowadays you can just create a custom build with the stuff you want. If yo…
Bling – the $ of jQuery without the jQuery
71–80 of 138 posts
Re: Bling – the $ of jQuery without the jQuery
#72Earlier quoted context omitted.
A very simple rule - if line starts with '[' or '(', put semicolon before. Thats it. Personally, if all is encapsulated inside self executing function, i put one semicolon before and one after it.
What about this? function v(x) { return x; } v("yeah"); returns undefined
Re: Bling – the $ of jQuery without the jQuery
#73This does three things: 1. Alias document.querySelectorAll to $. 2. Alias node.on to node.addEventListener. 3. Make NodeList a sub-type of Array (so you can use forEach etc on node lists as you would on arrays). The $ of jQuery also does a few other things, e.g. create HTML elements from text ($(' ') creates a div element with CSS class "foo") and wrap elements in a node list ($(document.body) creates a node list con…
wrap elements in a node list This is not correct. You may say that it wraps or outputs elements in a node list like object but it is not the real deal. If you examine the emitted jQuery objects using instanceof or any other method, you'd see that they are not related to NodeList in any way. They're just generic objects of Object type.
Re: Bling – the $ of jQuery without the jQuery
#74Yes, you can re-implement jQuery in 10 lines of code... if you only support 0.1% of the functionality of jQuery. jQuery was a game changer for web client side development. Thousands of work hours have been spent on it. It had a specially important role of dealing with all the inconsistencies between browsers. If you don't use all the features, nowadays you can just create a custom build with the stuff you want. If yo…
wow, storm in a tea cup much? He clearly mentions implementing '$', and nothing else ...
If behaviour is considered irrelevant, here's my one-line implementation of $:
var $;Re: Bling – the $ of jQuery without the jQuery
#75Earlier quoted context omitted.
wrap elements in a node list This is not correct. You may say that it wraps or outputs elements in a node list like object but it is not the real deal. If you examine the emitted jQuery objects using instanceof or any other method, you'd see that they are not related to NodeList in any way. They're just generic objects of Object type.
True, jQuery doesn't use the native NodeList for various reasons, but since QSA returns a NodeList, that'd be the equivalent for this "substitute".
Those reasons being:
* because it's garbage
* because native objects shouldn't (and may not necessarily be) extended
* because static nodelists didn't even exist back when jquery was created
* because you can't create a nodelist in userland code
Re: Bling – the $ of jQuery without the jQuery
#76Earlier quoted context omitted.
> "document.querySelectorAll(selector)" is a bit verbose Right. 35 characters. > "…but jQuery API is no better" Your jQuery example is 11 characters. I can’t believe you’re using verbosity as a measurement, while at the same time claiming 35 and 11 are the same. Does. Not. Compute.
Sorry for confusion, what i meant was: yes DOM API is a bit verbose, but jQuery is exactly the opposite in a bad sense: it's using too few words to express too many different things.
Re: Bling – the $ of jQuery without the jQuery
#77Earlier quoted context omitted.
What about this? function v(x) { return x; } v("yeah"); returns undefined
What about it? Yes, it returns undefined. Has nothing to do with semicolons. You can add semicolon to every line of your example, or remove each and every one and still it returns undefined.
Newline matters / doesn't matter, the same with the semicolons.
Re: Bling – the $ of jQuery without the jQuery
#78Earlier quoted context omitted.
I prefer:- function $(q, parent) { return (parent || document).querySelector(q); }
I'd also wrap it in a `[].slice.call`: function $(q, parent) { parent = parent || document; return [].slice.call(parent.querySelectorAll(q)); }
Array.from()
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...Re: Bling – the $ of jQuery without the jQuery
#79Earlier quoted context omitted.
(var | let | const) $ = ::document.querySelector; with experimental ES7 syntax :D https://github.com/zenparsing/es-function-bind
Huh, my joke actually turned into me learning something, thanks!