Lojic Technologies

Douglas Crockford: Advanced JavaScript

leave a comment »

Ok, last of the Douglas Crockford videos. These are definitely worth viewing if you program at all in JavaScript. The highlight for me was his presentation of prototypal and parasitic inheritance models and contrasting them with the pseudo-classical approach that is typically presented. I haven’t had time to analyze his approach in depth, but from a single viewing, his ideas certainly merit experimentation and seem to fit in more naturally to the JavaScript language.

I felt he did a good job of presenting natural ways of handling encapsulation, inheritance and code reuse while capitalizing on JavaScript’s strengths instead of trying to impose a class-based design onto the language. He also covered several ways of utilizing closures nicely.

function object(0) {
  function F() {}
  F.prototype = o;
  return new F();
}
newobject = object(oldobject);

var singleton = function () {
  var privateVariable;
  function privateFunction(x) {
    ...privateVariable...
  }
  return {
    firstMethod: function (a,b) {
      ...
    },
    secondMethod: function (c) {
      ...
    }
  };
}();

Object.prototype.later = function(msec, method) {
  var that = this,
      args = Array.prototype.slice.apply(arguments, [2]);
  if (typeof method === 'string') {
    method = that[method];
  }
  setTimeout(function () {
    method.apply(that, args);
  }, msec);
  return that;
};

Advanced JavaScript Part 1 of 3
Advanced JavaScript Part 2 of 3
Advanced JavaScript Part 3 of 3

Written by Brian Adkins

May 17, 2007 at 10:38 pm

Posted in programming, video

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: