jQuery supports an extend method (http://api.jquery.com/jQuery.extend/), which mimics multiple inheritance by allowing you to extend an object with the properties of as many objects as you want. This only mimics multiple inheritance, because it essentially uses a for-loop to iterate over the properties of the other objects and attaches them to the targeted one -- if it actually provided multiple inheritance, you would be able to add/remove/modify attributes from one of the super objects and have the changes inherited by the sub object, but that isn't the case.
To use jQuery.extend, you provide the target object as the first parameter, and the others with which to extend it as following parameters. Be careful, though, because if you only specify the first object, all the object's properties will be used to extend jQuery itself.
(function($) {
var SuperOne = {
methodOne: function() {
alert("I am an object");
},
methodTwo: function(param) {
// do something
}
},
SuperTwo = {
attributeOne: 'I am a super object',
getAttributeOne: function() {
return this.attributeOne;
},
setAttributeOne: function(attributeOne) {
this.attributeOne = attributeOne;
}
},
SubOne = $.extend({
subMethodOne: function() {
return 'I inherit from others.';
}
}, SuperOne, SuperTwo);
alert(SubOne.getAttributeOne()); ///<-- alerts, "I am a super object"
SuperTwo.setAttributeOne("I am SuperTwo!");
alert(SubOne.getAttributeOne()); ///<-- alerts, "I am a super object", still
SuperOne.methodOne = function() {
alert("I am SuperOne!");
};
SubOne.methodOne(); ///<-- alerts, "I am an object", instead of, "I am SuperOne!"
}(jQuery));