6

I'm looking for an open-source JavaScript project from which I can learn about good coding practices, patterns, etc.

For example, the equivalent 'awesome code' example from Java would probably be the Spring project internals.

I've thought about taking a look at prototype / jquery, but are there any better ones (by better I mean greater return on time invested)?

I'm talking proper substance as you would find in a java / ruby project, as opposed to a 50 line snippet of code to animate my buttons - (Sorry that's probably a bit JavaScript-ist).

2
  • Since you're looking for "good" code (best practices, patterns), I'd also recommend taking a look at the book "Javascript: The Good Parts" in addition to the code in the wild you're hunting for now. Commented Jul 27, 2010 at 23:39
  • Already reading it as we speak ;) - thanks anyway Commented Jul 27, 2010 at 23:52

4 Answers 4

2

It seems like everyone has a different approach when it comes to javascript. In general I find the node.js source code to be pretty clean and straightforward... It's not browser scripting, which I think gives a good picture of 'pure' javascript code that doesn't mess with host objects or the DOM.

http://github.com/ry/node/tree/master/lib/

Sign up to request clarification or add additional context in comments.

Comments

1

updated answer post comment discussion

Reading one of the popular general purpose libraries would be instructive in it's own way, but if you just want to learn solid JavaScript, I would go with something else. There are lots of projects to choose from.

Three interesting ones (to me, subjective remember :D)

  • processing.js
  • raphael.js
  • node.js

I think picking two projects that do similar things and comparing how they accomplish things would be a good way to learn what makes good js code.

8 Comments

Ok thanks. I understand it's my fault for leaving the question so wide open - but would any provide greater benefit over any of the others. For example : -More modern coding style. -Quicker return on time invested.
@lucas1000001 well, lots of people use jquery, so finding help might be easier. node and raphael are newer, so the 'fanatics' will jump to help you with the new cool shiny library. But other than that, I would say spend an hour or two looking at the code for a few, pick one and go with it.
Don't waste your time with GP libraries like jquery, prototype, moo tools. Too general functionality, too many compatibility hacks. Learn the language first and the browser quirks later. Start with a non-browser-related, non-GP script.
@Lucas - no matter how popular they are, I think they're the wrong thing to study for sample code. There are plenty of projects out there that don't deal with the DOM or with browser quirks, that do follow best practices. Something like an implementation of a well-known algorithm or library ported from another language to js would, IMO, be the best way to learn js (the language)... focus on a simple, understandable domain so you don't have to think about that, you can just think about the code.
@Matt: all of the GP libraries contain stuff that will make you shudder. It's hard for me to believe that the folks recommending these scripts as good learning samples for beginners have ever seriously looked at those codebases.
|
0

JQuery is definitely a nice piece of code. You might also want to look at CKEditor (http://ckeditor.com/), it was also written by skilled JS programmers using best practices.

1 Comment

Have you read the jQuery source? It's nowhere near a ‘nice’ piece of code. It's a confusing maze of browser bug workaround hacks and ugly speed optimisations. That's not necessarily a criticism, given what it's trying to do, but it makes it utterly unsuitable as a teaching aid.
-1

If you are looking to learn about the language then jQuery all the way. It will show you about the language and some of the ways you can bend JavaScript especially as it relates to the dom. If you want to look at what non-browser javascript is like then look into what is going on with Node.js and the code that can be written with that.

But really there is no wrong answer. At least in regards to the major js libraries out there. Though I have only gone over jQuery, Prototype, and YUI I'm sure the quality is high for the other ones like Dojo, MooTools and what not.

1 Comment

I really wouldn't use the jQuery source as a learning tool. It's hard to read and by its very nature is a repository of workarounds, some of which leave room for improvement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.