I am reading the source of jQuery UI,
$.widget = function( name, base, prototype ) {
var namespace = name.split( "." )[ 0 ],
fullName;
name = name.split( "." )[ 1 ];
fullName = namespace + "-" + name;
///parameter shifting
if ( !prototype ) {
prototype = base;
base = $.Widget;
}
...}
The semantics here is to support optional parameter base,
you can do $.widget(name, prototype) or $.widget(name, base, prototype)
the idea is good, but what is odd is that the position of optional parameter is in the middle of function, but not the last one. We should support calls like
$.widget(name, prototype) or $.widget(name, prototype, base)
$.widget = function( name, prototype, base) {
//..
if (!base) {
base = $.Widget;
}
//..
}
But since this interface has been used already, refactory is almost impossible, as it change the semantics and will break other code. My idea is that optional parameter should be the last one, is this good or bad?
Thanks