Activate your free membership today | Log-in

Thursday, July 10th, 2008

Code specialization; Namespaces again; Parasitic inheritance

Category: JavaScript

Karl Krukow has a new blog that has some interesting Ajax content. Rather than pick at one, we have a synopsis of a few of his recent posts:

Manual code specialization

A technique is presented (in terms of examples) which can give performance boosts in certain situations. The technique relies on higher-order functions, and sharing variables in closures.

Namespacing again

Namespacing has been generally accepted (in one form or another) as a good thing. In this posting, a pair of functions: 'namespace' and 'using' are presented. The former ensures the existence of a namespace, similar to what is offered in common JavaScript libraries. However, it accepts more general forms of namespace declarations:

JAVASCRIPT:
  1.  
  2. namespace({
  3.  com: {
  4.    trifork: {
  5.     tribook: ['model','view','controller']
  6.     }}});
  7.  

The latter function 'using' complements the namespace function. It brings a namespace into scope.

JAVASCRIPT:
  1.  
  2. using(com.trifork.tribook.model).run(function(m) {
  3.  
  4.  m.Reservation = function(start,end){
  5.   //...
  6.  };
  7. });
  8.  

Parasitic inheritance & instanceof

The object function advocated by Crockford in his work on parasitic inheritance makes a new object which has the input object as it's prototype. However 'instanceof' doesn't work with this function. A technique for combining these two is presented.

Posted by Dion Almaer at 10:37 am

+++--
3.5 rating from 18 votes

Comments Here »

Comments feed TrackBack URI

Leave a comment

You must be logged in to post a comment.