Wednesday, April 6, 2011

Remedial JavaScript

Direct from the master :-)
(...)The JavaScript Programming Language suffers from premature standardization. It was rushed to market and then instantly had a huge user base and, soon after, a formal international standard. There was no time during its development to polish the language. As a result, it still has some rough spots. (...)


I specially like

if (!String.prototype.supplant) {
   String.prototype.supplant = function (o) {
      return this.replace(/{([^{}]*)}/g, 
           function (a, b) { var r = o[b]; 
                return typeof r === 'string' 
                    || typeof r === 'number' ? r : a; } );
      }; 
   }

http://javascript.crockford.com/remedial.html

No comments:

Post a Comment