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
Tags: javascript, programming

Add a comment
Comments feed for this article
Trackback link: http://lojic.com/blog/2007/05/17/douglas-crockford-advanced-javascript/trackback/