Revision: 54994
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 20, 2012 14:31 by Glycerine
Initial Code
/*
* A little help function for when I'm creating functions
*
* When I pluck values from function arguments I tend to
* write content of this function repeatedly.
*
* e.g.
* a = arguments
* this.id = arg(a, 0)
* this.name = arg(a, 3)
*
* this.id == 6
* this.name == null
*/
function arg(_a, ia, def, returnArray) {
var v = null
// if ia is an array, find the
// first correct definition
if (ia.constructor == Array) {
/*
* Each item is checked. if the
* item in the array is
* a definition within the oaet
* arguments or object - pass it
*/
for(var i=0; i<ia.length; i++) {
if(_a[ia[i]]){
v = _a[ia[i]];
break;
}
}
}
else {
// if ia is just a value
if(_a[ia]) v = _a[ia];
}
if( (v == null) && (def != undefined) ) {
v = def
}
if(returnArray){
return [v, ia[i]]
}
else
{
return v
}
}
Initial URL
Initial Description
/* * A little help function for when I'm creating functions * * When I pluck values from function arguments I tend to * write content of this function repeatedly. * * e.g. * a = arguments * this.id = arg(a, 0) * this.name = arg(a, 3) * * this.id == 6 * this.name == null */
Initial Title
javascript function argument handling
Initial Tags
Initial Language
JavaScript