JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.11.0.css">
<script src="http://code.jquery.com/qunit/qunit-1.11.0.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.3/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.10/backbone-min.js"></script>
<h1>Backbone.js Views Multiple Inheritance</h1>
<h2>Applying the Backbone.js Views test suite to a multiple inheritance technique proposed on <a href="http://stackoverflow.com/a/7736030/741970">Stack Overflow</h2>
<h1 id="qunit-header">Backbone Views Multiple Inheritance</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture"></div>
JavaScript
// ---------------------------------------------------------------------
// Objects to test
// Concept from http://stackoverflow.com/a/7736030/741970
// ---------------------------------------------------------------------
var RegularView = function (options) {
// All of this code is common to both a `RegularView` and `SuperView`
// being constructed.
this.color = options && (options.color || 'Green');
// If execution arrives here from the construction of
// a `SuperView`, `Backbone.View` will call `initialize`
// that belongs to `SuperView`. This happens because here
// `this` is `SuperView`, and `Backbone.View`, applied with
// the current `this` calls `this.initialize.apply(this, arguments)`
Backbone.View.apply(this, arguments)
};
RegularView.extend = Backbone.View.extend;
_.extend(RegularView.prototype, Backbone.View.prototype, {
// Called if a `RegularView` is constructed`,
// Not called if a `SuperView` is constructed.
initialize: function () {
console.log('RegularView initialized.');
},
say_hi: function () {
console.log('Regular hi!');
}
});
var MidSuperView = RegularView.extend({
// Called if a `SuperView` is constructed`,
// Not called if a `RegularView` is constructed.
initialize: function (options) {
console.log('SuperView initialized.')
},
say_hi: function () {
console.log('Super hi!');
}
})
var SuperView = MidSuperView.extend({
initialize: function (options) {
console.log('SuperDuperView initialized.')
},
say_hi: function () {
console.log('SuperDuper hi!');
}
})
var regular_view = new RegularView({
color: 'Violet'
})
var super_view = new SuperView({
color: 'Super violet'
})
// ---------------------------------------------------------------------
// Backbone.js View Test Suite
// (Accessed on 12 March 2013, and adapted to above-listed objects from:
// ...