Tag Archive for argument

Pass a stream to a function #2

void myfunction(ifstream &fp, ...)  // use this
void myfunction(ifstream fp, ...)   // not this

source

Optional Parameters and Default Arguments

function testFunction(a,b,c) {
// this says 'if the type of a is undefined, set it to '', otherwise set it
// to a (e.g. itself)'
a = (typeof(a) == undefined) ? '' : a;
b = (typeof(b) == undefined) ? '' : b;
c = (typeof(b) == undefined) ? '' : c;
}

source

Option Hash Using jQuery

var complex = function(valA, options){
/**
* Set the default values in the object, then extend it to include the
* values that we passed to it.
*/
var settings = $.extend({
option1: null,
option2: null,
option3: null,
option4: null
},options||{});//If no options, pass an empty object
console.warn(valA);
console.log(settings.option1);
console.log(settings.option2);
console.log(settings.option3);
console.log(settings.option4);
};
complex('Value A', {option1: 'this is option 1'});

source