Have a series of functions, each of which parses its arguments identically. right now this parsing chunk is cut and pasted to the beginning of each function. Is there a better way to do this?
Post.update = function( e ) {
// parse args
var e, el, orig_el, args, render, callBack;
for( var i=0; i<arguments.length; i++ ) {
if( arguments[i] instanceof HTMLElement ) orig_el = arguments[i];
else if( arguments[i] instanceof Render ) render = arguments[i];
else if( arguments[i] instanceof Event ) {
e = arguments[i];
orig_el = orig_el || e.target;
}
else if( typeof arguments[i] == 'function' ) callBack = arguments[i];
}
// Post.update work here
}
Post.verify = function( e ) {
// parse args
...
// Post.verify work here
}
The reasons arguments are parsed instead of passed individually are that, with five+ possible args
I'm prone to make mistakes in ordering and omission calling funcs with a long list of args
changing one argument to the function means changing every call to the func
imho a function with five arguments is quite unreadable compared to passing exactly what's necessary
So my goal is to abstract the parse section of the functions while maintaining the clarity of the function calls as they are now.