I've been playing with javascript recently and I'm trying to come to grips with the advantages of pseudoclassical inheritance (as described by Crockford using the prototype property of objects). Crockford says he rarely uses it and prefers the functional approach, that is, creating a function that augments an object like
var obj = function() {
var self = {};
self.method = function() {
};
return self;
}
I prefer this approach, it's easier to understand and seems flexible.
However, I see lots of code that still use the prototype property, including popular frameworks like jQuery. I'm wondering what are the advantages? My understanding of using prototype property is that it gives us the ability to ask whether an object is a particular type by traversing the prototype chain. However, being a dynamic language, wouldn't it be better to ask if an object can do something, rather than what it is?