-
1. Re: Multiple inheritance with RichFaces javascript objects
nbelaevski Jul 20, 2011 6:11 PM (in response to bleathem)Brian,
I'm using delegation instead of multiple inheritance - it's much simpler to maintain.
Extend(parent, child) method you are referring to overrides prototype chain, so it is not safe to call it for different base classes. Better use hash that contains combined methods as prototype.
-
2. Re: Multiple inheritance with RichFaces javascript objects
bleathem Jul 20, 2011 6:10 PM (in response to nbelaevski)Thanks Nick! That'd work well too.
Can you point me to a particular component that already makes use of delegation?
-
3. Re: Multiple inheritance with RichFaces javascript objects
nbelaevski Jul 20, 2011 6:18 PM (in response to bleathem)probably not the best example, but anyway: JavaScript Tree class that delegates reponsibilities to TreeNodeSet.
-
4. Re: Multiple inheritance with RichFaces javascript objects
bleathem Jul 20, 2011 7:48 PM (in response to nbelaevski)That worked great - thanks Nick!
For those interested, my popupList.js now looks like:
(function ($, rf) { rf.ui = rf.ui || {}; rf.ui.PopupList = function(id, listener, options) { this.namespace = this.namespace || "." + rf.Event.createNamespace(this.name, id); var mergedOptions = $.extend({}, defaultOptions, options); $super.constructor.call(this, id, mergedOptions); this.list = new rf.ui.List(id, listener, options); }; rf.ui.Popup.extend(rf.ui.PopupList); var $super = rf.ui.PopupList.$super; var defaultOptions = { attachToBody: true, positionType: "DROPDOWN", positionOffset: [0,0] }; $.extend(rf.ui.PopupList.prototype, ( function () { return { name : "popupList" } })()); })(jQuery, window.RichFaces);
And I have list.js that contains all the previous popuplist javascript (except the default options). Thus, PopupList extends Popup to get the popup functionality, but PopupList is composed of a rf.ui.List object, which can in turn be used to build other components.
More testing is required, but this looks good so far!
DRY FTW !