.extend, not prototype for classes?

I've read an interesting article on DOM prototype extension, showing some good reasons to not always rely on prototypes of Element - I didn't know there were subclasses of elements, like

HTMLParagraphElement.prototype <- HTMLElement.prototype <- Element.prototype <- Node.prototype <- Object.prototype

In general, Object prototypes can be used for subclassing, but often I see _.extend used to create mixins or base-classes, for example as seen in the Backbone source code.

_.extend(Model.prototype, Events, {...stuff...}

Why was this used instead of something like:

function innerModel() { ...stuff...}
innerModel.prototype = Events

Model.prototype = innerModel

Is the lack of prototype-chain visualization and debugging in browsers a reason _.extend is often used for subclassing instead of object's prototype?

链接地址: http://www.djcxy.com/p/27240.html

上一篇: 用Object.create扩展本地JavaScript对象

下一篇: .extend,而不是类的原型?