There are couple more solutions as well. Depends on how deep do you want to go.
In my case I was intending to extend DataScroller's functionality.
Despite it's too late answering your question, I hope the solutions below helps others:
Solution #1 (extending entire class with its methods)
PrimeFaces.widget.DataScroller = PrimeFaces.widget.BaseWidget.extend({
init: function(cfg) {
this._super(cfg);
// only for widget with widgetVar="yourWidgetVar"
if(cfg.widgetVar === 'yourWidgetVar') {
this.yourCustomMethod();
}
},
yourCustomMethod: function() {
// do whatever you prefer here
}
});
Solution #2 (extending of already existing methods aimed to specific widgets)
PF('yourWidgetVar').load = function() {
// do whatever you prefer to extend it here
// call the generic implementation
PrimeFaces.widget.DataScroller.prototype.load.call(this, arguments);
};
Solution #3 (extending of already existing methods via prototypes)
const oldLoad = PrimeFaces.widget.DataScroller.prototype.load;
PrimeFaces.widget.DataScroller.prototype.load = function() {
oldLoad.apply(this, arguments);
// do whatever you prefer to extend it here
// in case you need to do it for specific widget. i.e. widgetVar="yourWidgetVar"
if(cfg.widgetVar === 'yourWidgetVar') {
// your custom stuff here
}
};
Solution #4 (overriding init
method of component)
if(PrimeFaces.widget.DataScroller) {
PrimeFaces.widget.DataScroller.prototype.init = function(cfg) {
PrimeFaces.widget.DeferredWidget.prototype.init.call(this, cfg);
this.cfg = cfg;
// this._super(cfg);
// original init method code without calling _super method
// apply here your custom code
}
}