Matt said:
I didn't look at the source closely enough. I thought they got rid of
accessing properties of elements and went purely to get/setAttribute.
I was incorrect. Disappointing.
Indeed, which has been David's criticism for a long time. It looks
like Resig still doesn't get it.
Didn't John Resig just make a post on jquery-dev about how he refuses to
read comp.lang.javascript?
It is hard to understand anything when the thing that is to be
understood is intentionally ignored.
$(':checkbox[name=foo]').run("this.checked==true");
run() is obviously a little eval wrapper that I plugged into jQuery.
That sounds dangerous.
Not if you know what you are doing. I use it for very simple things,
to avoid lots of anonymous functions.
Documented well
The w3c standards are at least as well documented.
There are some examples in HTML 4 spec.
Printed material available for developers to read from
Books?
An active support community
ciwas, ciwah, c.l.js.
Active development and bug fixing
Modern browsers have fixed many standards-related bugs in the past 10 years.
Supported by various editors and environments
etc
What do you want the library code to do?
If you're just a stand-alone developer choosing the best tool, jQuery
may not be the best pick. If you're trying to organize a team of 10-20
developers, some onshore some offshore, all of differing experience
levels, who all need to touch the js of the webapp, then having a tool
like jQuery is very important. In my experience, I have found that
without such a library the code quality is consistently lower and the
number of problems is way higher. jQuery sure has its problems, and
it's not a perfect solution, but it's way better than the other
alternatives I've found. When I find a better option, I'll switch.
That is where code reviews and pair programming come into play.
Code reviews do many things. They force the person who is doing the
review to look closely and understand th code. That right there is a
huge benefit because now two people understand the code. Code reviews
find bugs before they ship. This avoids QA churn. Code reviews can cause
the person writing the code scrutinize check their work more carefully
knowing someone is going to be scrunitize the work.
I once did blocking code reviews for the offshore team. Their HTML and
CSS ath te start of the project was awful. Towars the end, they were
much better than the in house guys. It was a huge success. Unfortunately
the inhouse people were fucking lazy. The laziness was demonstrated by
their hiring brows people overseas for sub-standard wage to do their
work while they took "OOO" or "WFH" days which were actually vacation
(Disneyland, etc).
The benefits of code reviews are also benefits for Pair. Now sometimes
pair is a waste of time, but it can be extremely productive. Pair may
include a little goofing, but usually not much.
A lot of people get nervious about code review but like pair. I guess it
depends who you are working with or who is revieing your code. The
decision to choose one over the other comes down to preference and
logistics (kind of hard to remotely pair).
Even if jQuery is used, there should be code reviews or pair. And for
code reviews with jQuery, it woul make sense to advise against using the
inefficient ready function, the inefficient selectors, the attr or
removeAttr functions, the inefficient animation. Possibly a bette way to
use jQueyr woul be:-
var el = document.getElementById("redBox");
wrappedEl = jQuery(el)[0];
This, at least, would avoid the initial inefficiency of finding the element.
The next step would be writing code that actually does something useful
to fulfill requirements.
That would be great, but I have no desire to write it. I know what
problems I have with jQuery, and I code around them. If I were being
paid for it, I would certainly write such an article
What is the reason for having jQuery in the first place?
The patterns jQuery encourages are:
1) wait for document ready,
2) select some nodes,
3) do something with nodes (add event callbacks, etc).
The design I have always favored is:
1) add an event callback to document
2) in the callback, if the target is something were' innterested in,
act accordingly (delegate to the relevant factory, etc).
This second type of design is much simpler and much more efficient.
There is not any query selector, no looping through each and every node.
No waiting for "ready". The only thing that happens while the page is
loading is a event handlers (click, etc) get attached.
Consider what jQuery actually does with ready, and then with:-
var el = jQuery("redBox")[0];
- compared to what happens with:-
var el = document.getElementById("redBox");
- or:-
if(hasClass(target, "ape-calendar")) {
Calendar.getById(target.id);
}
jQuery's ID Command checks each element to see if the ID matches the id
specified. The overhead of matching every element is proportional to the
size of the document. The larger the document, the slower jQuery will be
at matching. This is a much less efficient than document.getElementById.
Looping through the dom during page load can temporarily lock up the UI.
Google search had that problem for a few days but they seem to have
removed that feature.
The jQuery css selector ID matcher could use getElementById, but then it
would not match mutliple IDs. I don't see the point in matching multiple
IDs, but then again, I don't see much point in jquery at all. Perhaps
someone can explain it to me.
A piece of code should exist to solve a problem. In the case of jQuery
selector, the problem solved is finding an element.
The jQuery approach is much more complicated and much slower. It also
requires a significantly large dependency.