Secrets of the JavaScript Ninjas

@Joel F

I believe ninjas where often samurai on their night shift :wink:

If youā€™re writing a modern web app or adding some dynamic functionality to a site, use a library ā€“ there is not a single, solid argument against this. Youā€™ll save time by turning a blind-eye to browser consistency, creating DOM elements more easily and avoiding doing the same thing over and over again.

What concerns me is the tight coupling of JavaScript libraries to modern frameworks like Rails. Now that most of us web workers are in client-side scripting heaven, this is where I see the next big battle appearingā€¦unless youā€™re working with (the awesome) Django.

jQuery is by far the best library to use. Period.

Good post, I too have finally come around to using javascript heavily in my applications, and itā€™s 100% thanks to JQuery.

Having coded in various Javascript frameworks, JQuery is the only one that makes Javascript enjoyable.

Itā€™s the only one that looks as though itā€™s designed to work with the DOM: i.e. find object(s), then do something(s) with it/them.

The others generally look like Javascript: i.e. copying the syntax of an imperative language built to do anything and cope with a vast number of input types. Which is great, when you canā€™t count on the DOM being there. For everything else, thereā€™s JQueryā€™s approach.

I have been following and using ExtJS for about 18 months now and must admit that when I started was a javascript novice. Using this framework has been a revelation and has led me to actually learn javascript properly. I would recomend anybody to look at this highly polished framework which has excellent API documentation and a very friendly and helpful user community on its support forums.

Aaron, awesome, didnā€™t knew Google did that for you, thanks! Going to start using that :slight_smile:

Seems they even serve different versions, which you can select with a parameter :slight_smile: (http://code.google.com/apis/ajaxlibs/documentation/index.html)

Jeff Atwood allergic to writing his own code? Accusing those who do of being stupid?

Yawn. What else is new?

I for one think that marrying the server side to the client side will be a huge win for web developers - a server side framework that letā€™s me choose which client side lib I want to use to output rich UI widgets would be awesome. Say maybe YUI or Ext. That way I still get to choose which lib I prefer.

Letā€™s not forget about Aptana Jaxer either.

I picked up Prototype a little more than a year ago and was really impressedā€¦ Until I saw JQuery, which does a lot more with a smaller download. At this point, Iā€™d be strongly inclined to go with JQuery rather than prototype.

For some applications, however, these libraries are pretty large. Two years ago I wrote a simple 3-d engine in Javascript that uses AJAX to download geometry in XML format:

http://polyhedra.org/

The Javascript applet is an 8k download. Iā€™ve thought about rewriting to improve it in a number of ways, in particular to use binary-space-partitioning so it can correctly draw more difficult shapesā€¦ One obvious thing to do is to base it on a library like JQuery or Prototype, but then youā€™ve got an 8k applet that depends on a 20k or 40k library, which is a big increase.

These frameworks spackle over []

I guessed spackle was a euphemism for urinate, but was wrong.

smooths over, for non-US readers.

JavaScript used to be an unknown, weird, and scary due to its quirks. But once I learned about jQuery, I always look for opportunities to make use of it. Itā€™s just powerful and fun. Too bad my projects are using Prototype as the JS library of choice (itā€™s Rails after all). So most of the time, if itā€™s doable in Prototype, in Prototype it is done. Naturally, Prototype results in longer code than jQuery.

But above all, Firebug is for me the tool that makes JavaScript writable.

Actually, youā€™re one generation behind, Jeff. Not only Javascript works, itā€™s actually become assembly language and there is no longer any point in developing in it: just use GWT and not only do you get a fully statically typed and Eclipse supported development environment, but the generated Javascript is also extremely compact and filled with optimizations that would take hundreds of lines to write by hands (e.g. image bundles). And for these cases where you need to go to the metal, you can still drop down to the Javascript level whenever you have to.

I guess Iā€™m a Luddite or somethingā€¦

Not very long ago, we used to write software to solve problems. Now we spend the bulk of our time trying make widgets behave.

This is progress?

Not very long ago, we used to write software to solve problems.
Now we spend the bulk of our time trying make widgets behave.
This is progress?

Itā€™s the difference between re-inventing the wheel, and figuring out what size wheel is right for your bike/car/whatever. If every car manufacturer had to re-invent the wheel for every car they made, weā€™d have a lot less cards, so yes it very much is progress IMHO.

[caution] are those javascript ninjas on fire? /yikes

One interesting newer development along these lines is the rise of platforms such as Facebookā€™s FBJS and Googleā€™s Caja which though intended to provide a safe sandbox for Javascript code as a side effect also take care of abstracting out all of the browser compatibility issues.

Spackle is a brand-name substance for filling in cracks, pits, chips, and other imperfections, such as prior to painting a wall.

One could say smooth over insteadā€¦

Iā€™m a college student, but I have almost no web web development classes. Iā€™m interested in the area but I find really hard to start doing something. Just looking at the Javascript entry on wikipedia frightens me. Can anyone give me some hints as to where I can find some good introductory course of web development and javascript for someone who only knows C, some Java, data structures and pointer stuff? How can I integrate code made in server side with other languages to produce something that a browser can understand? Anyone who can point me some URLs to start diggin on my own I would appreciate.

I mean, cā€™mon look at this thing:
http://ejohn.org/files/ecma-cloud.png
Where do I start?

The few that I looked at all have the same problem: the bulk of the code was dedicated to providing fancy selectors, animation, etcā€¦ rather than a minimal browser abstraction layer.

The programmers just canā€™t stop themselves once they get started. Which I understand, but it seems like a lot of duplicated effort, and a missed opportunity for a minimal toolkit.