A strftime for Prototype
Object.extend(Date.prototype, {
strftime: function(format) {
var day = this.getUTCDay(), month = this.getUTCMonth();
var hours = this.getUTCHours(), minutes = this.getUTCMinutes();
function pad(num) { return num.toPaddedString(2); };
return format.gsub(/\%([aAbBcdDHiImMpSwyY])/, function(part) {
switch(part[1]) {
case 'a': return $w("Sun Mon Tue Wed Thu Fri Sat")[day]; break;
case 'A': return $w("Sunday Monday Tuesday Wednesday Thursday Friday Saturday")[day]; break;
case 'b': return $w("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec")[month]; break;
case 'B': return $w("January February March April May June July August September October November December")[month]; break;
case 'c': return this.toString(); break;
case 'd': return this.getUTCDate(); break;
case 'D': return pad(this.getUTCDate()); break;
case 'H': return pad(hours); break;
case 'i': return (hours === 12 || hours === 0) ? 12 : (hours + 12) % 12; break;
case 'I': return pad((hours === 12 || hours === 0) ? 12 : (hours + 12) % 12); break;
case 'm': return pad(month + 1); break;
case 'M': return pad(minutes); break;
case 'p': return hours > 11 ? 'PM' : 'AM'; break;
case 'S': return pad(this.getUTCSeconds()); break;
case 'w': return day; break;
case 'y': return pad(this.getUTCFullYear() % 100); break;
case 'Y': return this.getUTCFullYear().toString(); break;
}
}.bind(this));
}
});
UPDATE: Bugs fixed. Thanks Andrew and Stephen
Also, some of my old and new code has been posted on GitHub. You might find something useful.
Widgets the YUI Way
Why are there so many lightbox implementations? Why are there numerous “versions” of widgets? Do you know which fork is the latest and greatest? Probably not, and for good reason. The current system sucks.
Your Momma's So Fat...Prototype vs. JQuery Edition
The time has come once again to clear the air of fallacious statements by the myriad of people comparing Prototype to JQuery. I’m all for comparison; I believe it’s healthy to have choices in life. The problem usually isn’t Prototype or JQuery, it’s the article comparing them.
Upgrading Radiant to Prototype 1.6
Mislav has written up an excellent overview on upgrading Radiant (which used 1.5) to Prototype 1.6. The article does a great job of showing how 1.6 is superior to 1.5.
Prototype Inheritance Updates
Defining classes and inheritance in Prototype–Incase you’ve missed it, Prototype 1.6 has a new inheritance model.
Understanding Scope and Binding in JavaScript
At the heart of binding, it’s merely a means to control execution scope—Function x executions in the scope of object y. It can be tough to grasp at first, but with the right amount of ninja references, anything can be explained so someone can understand it.
Prototype Bungee Book Released (And I'm late announcing it)
Prototype:The Bungee Book Lands —If you don’t know Prototype, get this book. If you know Prototype, get this book. It’s that good.
Shortcuts for the new Prototype DOM Builder
// Lowpro style (http://www.danwebb.net/2007/4/16/low-pro-0-4-released)
$w('a div p form').each(function(e) {
window['$' + e] = function() {
return new Element(e, arguments[0]);
}
});
// $form({action: '/foo', method: 'post'});
New DOM Builder in Prototype
Let the DOM Cometh —New DOM builder in Prototype’s trunk.
PeepCode: Prototype Video Training
PeepCode Video: JavaScript With Prototype—In-depth video training for Prototype.
Prototype 1.5 Released and Documentation Site Live
We’ve worked really hard getting the official Prototype site up and running and it’s finally here, not to mention we’re also releasing 1.5!
Inject and Pluck: The Secret Sauce Behind Prototype's Enumerable
No misspelling in that title. Two of the most underused, albeit powerful, methods of Prototype are pluck and inject. Pluck provides an easy way to get at data, and inject is like the duct tape of Prototype—applicable in a variety of cases. Let’s look at how these methods can help tidy up our code and make our life a little easier.
Avoiding Bloat in Widgets
Widgets walk a fine line between abstractions and implementations. Implementation, in this case, is a practical solution chosen to perform a given function. The problems with widgets occur when the widget author walks too far in one direction, or worse, walks an outward spiral covering both directions. Both choices lead to script bloat and complexity thats hard to manage. You no longer have a simple solution for a defined problem, you have a complex solution for a variety of problems. The good news is there are ways to avoid both the bloat and complexity.
Prototype: A Call For Documentation
We’re hard at working getting the Prototype documentation site ready for launch. However, we know there is already a lot of great documentation scattered throughout the web. Instead of us rewriting a lot of this documentation, we’d like to ask that the community lend us a helping hand.
More Ruby in Prototype
It’s obvious that Ruby has been a big influence to Prototype. We’ve already talked about Enumerables, Arrays, and Hashes, and how powerful they are. Now, lets look at some new tools: inGroupsOf and eachSlice.

