Skip to content

Instantly share code, notes, and snippets.

@ericrrichards
ericrrichards / gist:4066113
Created November 13, 2012 14:49
Javascript default params
function Foo( a, b, c, d, e ){
a = typeof a !== 'undefined' ? a : 0;
b = typeof b !== 'undefined' ? b : 0;
c = typeof c !== 'undefined' ? c : 0;
d = typeof d !== 'undefined' ? d : 0;
e = typeof e !== 'undefined' ? e : 1;
return (a + b + c + d ) / e;
}
function Foo( args ){
var a = 0;
var b = 0;
var c = 0;
var d = 0;
var e = 1;
if ( args['a'] ) a = args['a'];
if ( args['b'] ) b = args['b'];
if ( args['c'] ) c = args['c'];
if ( args['d'] ) d = args['d'];
@ericrrichards
ericrrichards / gist:4066073
Created November 13, 2012 14:41
Default Parameters
void Foo( int a, int b, int c = 0, int d = 0, int e = 1){
return (a + b + c + d)/e;
}
@ericrrichards
ericrrichards / gist:4066061
Created November 13, 2012 14:38
Function Overloading
void Foo( int a, int b, int c, int d, int e){
return (a + b + c + d) / e;
}
void Foo ( int a, int b ){
return Foo(a, b, 0, 0, 1);
}