4 Feb
JavaScript namespaces
Based on the Prototype namespacing made easy, except this doesn't require Prototype.
String.prototype.namespace = function(separator) {
var ns = this.split(separator || '.'), p = window, i;
for (i = 0; i < ns.length; i++) {
p = p[ns[i]] = p[ns[i]] || {};
}
};
This isn't so much to ditch Prototype, but to encourage using namespacing.
You should follow me on Twitter here I'll tweet about JavaScript, HTML 5 and other such gems (amongst usual tweet-splurges)
Introducing HTML5
Nicely done.
The "i=0" in the for loop should be declared as "var i=0", otherwise "i" becomes set at the global level - exactly what namespaces should be preventing.
@Mark - how on earth did I miss that! Corrected now - cheers.