within a function, how to discern between a non-arg and an undefined arg?
myFunc( 'first' );
var obj = { a: 123 };
myFunc( 'first', obj.b );
_or_
myFunc( 'first', undefined )
Can be solved easily with arguments.length
refers to arguments past the named arguments, so it's no helparguments.length
- sorry about the brain fart!
function myFunc( a, b ) {
// Case A: if no second arg, provide one
// should be: if( arguments.length < 2 ) ...
if( b === undefined ) b = anotherFunc;
// Case B: if b is not resolved - passed but undefined, throw
else if( b === undefined ) throw( 'INTERNAL ERROR: undefined passed' );
// Case C: if b not a function, resolve by name
else if( typeof b != 'function' ) { ... }
...
}
What is the correct way to capture Case A and Case B in myFunc
?