views:

346

answers:

3

On Stackers' recommendation, I have been reading Crockford's excellent Javascript: The Good Parts.

It's a great book, but since so much of it is devoted to describing the best way to use Javascript's basic functionality, I'm not sure how I can put his advice into practice without duplicating the efforts of many other Javascript programmers.

Take this passage, for example:

When you make a new object, you can select the object that should be its prototype. The mechanism that Javascript provides to do this is messy and complex, but it can be significantly simplified. We will add a create method to the Object function. The create method creates a new object that uses an old object as its prototype.

if (typeof Object.create !== 'function') {
 Object.create = function(o) {
  var F = function () {};
  F.prototype = o;
  return new F();
}

I could manually add this code to all my Javascript projects, but keeping track of everything would be a huge pain.

Are there any libraries that implement The Good Part's recommendations and thereby save me the trouble of having to keep track of them (/ physically type them all out)?

+3  A: 

Prototype has many great features, including a Class helper that handles the details of JS "inheritance" via the object prototype.

Edit: damn, I keep forgetting that jQuery (my own library of choice) has jQuery.extend

Tautologistics
+1  A: 

Doesn't he work for Yahoo? You could always use the Yahoo User Interface libraries.

Personally, I'm partial to JQuery, as it strikes me as more concise, but you know: horses for courses.

Travis
+1  A: 

Dojo has followed Crockford's ideas very closely. For example, there is an implementation of the code snippet you have above implemented under the function dojo.delegate (in an even faster form).

I don't think there's a specific project that follow his recommendations to a tee. Most of the toolkits actually disagree with quite a few of his recommendations and patterns. If you're wondering about specific functionality, like that code snippet above, it would be worth asking about which specific tools from the book you want to use in your projects.

pottedmeat