Plugin-plugins - Making mixins easier via varargs

Plugin-plugins - Making mixins easier via varargs


Currently the main way to create new widgets by reusing existings
(both prototype inheritance and delegation) involves using $.extend,
which usually results in some ugly calls like this:
$.widget(name, $.extend({}, otherProperties, { newstuff })
$(...).someWidget($.extend({}, mynewDefaults, someOtherStuff));
Both cases we could just pass through arguments to $.extend, enabling
varargs for both $.widget calls as well as init methods. The change
shouldn't effect existing implementations at all.
A plugin could then provide different configurations as public
properties, either bundled in the core file or as addons. For example,
the autocomplete could come with a from-select configuration:
$(...).autocomplete($.autocomplete.fromSelect, {
// custom stuff for this one
});
$.autocomplete.fromSelect could be provided by ui.autocomplete.js, or
as a seperate file, eg. ui.autocomplete.select.js.
Or you build a new widget that extends a dialog:
$.widget("newDialog", $.dialog.prototype, {
// new methods
});
The order of the arguments would be significant, just as for $.extend.
The implementation could check arguments.length and apply $.extend
only when there is more then one argument.
Making the $.extend call implicit is similar to how jQuery does
implicit iteration.
With that in place we'd probably just need a way to have multiple
init-functions to provide plugin-plugins...
Jörn