views:

256

answers:

8

Hey Everyone,

I'm new to javascript (functional programming is okay for me, though) and I am wondering how jQuery got away with some of the design decisions they made. Is it just too much work to fix now or what? For instance, there seems use of strange symbols in strings when accessing elements in the DOM or weird function definitions for $, that are forcing me to check references every other time I want to get some basic data.

Can someone point me to a learning source where I can learn all of these nuances of jQuery (jQuery's examples just don't cut it, they're too spread out)? Maybe someone has a super good reference site/pdf for jQuery?

Thanks

EDIT:

And as a side point, in regards for learning, why the heck is the entire jquery.js file collapsed onto a single line? It is unreadable.

A: 

You have seen jquery.com right?

griegs
Well, yeah, but their examples are so contrived and spread out - they illustrate how to do ONE thing in each example, and have a thousand of them.
gnucom
What do you expect? They are EXAMPLES. It's their purpose to explain one single thing.
Techpriester
yeah @gnucom we've all been through this and seemed to have no problem with the examples. i think you should go through one or two of them and get a feel for the syntax.
griegs
+7  A: 

Try reading jQuery in Action, it's a really good book to get started with jQuery. Next to that you can also watch examples on jquery.com, but I did prefer the book to get started. For JavaScript basics you can try w3schools.

In the beginning I had the same problem with the $ functions etc, but after I read the book it became all clear to me, and to be honest, I wouldn't use plain JavaScript without jQuery anymore for DOM manipulation.

For your edit: you have a compressed (or minified) version, which has all code on 1 line, most spaces removed etc to keep it small and a readable version. Both files can be found on the download page from jQuery.

Bart
Note that [W3C](http://www.w3.org/) has **nothing** to do with W3Schools...
CMS
I actually use jQuery instead of $, but not always
elcuco
You're right CMS, changed the typo :)
Bart
A: 

start on jQuery Docs Main page...

Reigel
A: 

You could try some other JavaScript frameworks to find out which one suits you best.

Although jQuery is pretty cool for most people, it's not the holy grail for everyone.

Maybe it's just not "your thing".

Techpriester
Haha, nice. Any in mind?
gnucom
dojo ext js mootools. I tried dojo, but switched to jquery due to market demand and ease of use and its modular structure. You start of with relative small core with all kinds of possible extensions.
dr jerry
+6  A: 

The strange symbols you refer to are mostly CSS selectors, the standard way to address elements on the web. jQuery could've come up with its own conventions, but decided to go with what was standard and best known.

jQuery itself is surprisingly consistent. Once you wrap your head around the jQuery style you barely have to consult the documentation; things just work as you'd think they should.

The jQuery documentation is actually quite good and includes an example with every command. It also has a large user base, so a quick search will generally answer any questions you have. Google is your friend.

I'm guessing the issue is not jQuery, but a difference in javascript style compared to languages you're more familiar with. Watch Crockford's "Javascript: The Good Parts" for a reasonable introduction to good javascript style.

http://video.yahoo.com/watch/630959/2974197

Also check out Dustin Diaz's posts, I found his early screencasts where he'd build an app and talk about what he was doing very educational:

http://www.dustindiaz.com/

Parand
+1 Google is my friend too...
Reigel
+2  A: 

I think jqapi.com is a more useful jQuery API documentation resource than jquery.com

kristian
I find this much more useful than the hundreds of silly examples they have, thank you very much for this resource!
gnucom
+1  A: 

Compressed javascript uses less bandwidth to load up, and decreases load times. Use js beautifier to expand it.

jQuery is the greatest thing to happen to the DOM API, which is just awful to deal with. It also handles cross-browser issues and older versions, giving them functionality they otherwise wouldn't have.

The strange symbols in selectors are from CSS, not the fault of jQuery. The selectors API is now being built into browsers, so it's worth it to understand what they mean.

x1a4
you can also simple download the uncompressed 'development' version from the jquery website
HorusKol
That answer was more of a general 'why does so much javascript show up on one line' answer.Interestingly, Google's closure compiler actually inserts linebreaks every 500 of so characters to get around proxies that choke or deny large, single line js files. http://code.google.com/closure/compiler/faq.html#linefeeds
x1a4
+1  A: 

As for a functional programmer every imperative language is probably a failure in your eyes and mindbending to capture, with javascript and jquery probably on top of that list. They both have side effects all over. Jquery is really about manipulating the DOM so the side effects are the means and the goal, as opposed to proper functional programming. If you're young enough you can still make the mind switch though :-)

dr jerry