ifnotundef
A set of helper functions that simplify the (is a undefined ? b : c) syntax
Author: Loïc Formont
License: MIT Licensed
Example
var undef = ;
- ifnotundef
- .if(a, b, [c]) ⇒
*
- .is(a, b) ⇒
boolean
- .isnot(a, b) ⇒
boolean
- .check(a, b) ⇒
boolean
- .try(a, [b]) ⇒
*
- .child(a, b, c, [d]) ⇒
*
- .if(a, b, [c]) ⇒
*
undef.if(a, b, [c]) ⇒ Two parameters mode If a is undefined, return b else a Three parameters mode If a is undefined, return c else b
Kind: static method of ifnotundef
Returns: *
- a, b or c depending on their undefined status
Param | Type | Description |
---|---|---|
a | * |
the first parameter |
b | * |
the second parameter |
[c] | * |
the third parameter |
Example
Two ways to use if. Either with two parameters (a||b):
var myHost = undef;
or with three parameters (a?b:c):
var myHost = undef;
boolean
undef.is(a, b) ⇒ Invert of "check"
Kind: static method of ifnotundef
Returns: boolean
- a or a[b]'s undefined status
Param | Type | Description |
---|---|---|
a | * |
the variable to check |
b | * |
the child path |
Example
ifundef console;
boolean
undef.isnot(a, b) ⇒ Alias of "check"
Kind: static method of ifnotundef
Returns: boolean
- a or a[b]'s undefined status
Param | Type | Description |
---|---|---|
a | * |
the variable to check |
b | * |
the child path |
Example
ifundef console;
boolean
undef.check(a, b) ⇒ One parameters mode If a is undefined, false else true Two parameters mode If a[b] is undefined, false else true
Kind: static method of ifnotundef
Returns: boolean
- a or a[b]'s undefined status
Param | Type | Description |
---|---|---|
a | * |
the variable to check |
b | * |
the child path |
Example
if!undef console;
*
undef.try(a, [b]) ⇒ One parameters mode If a is undefined, throw a else return a Two parameters mode If a is undefined, throw b else return a
Kind: static method of ifnotundef
Returns: *
- a or exception depending on a's undefined status
Param | Type | Description |
---|---|---|
a | * |
the parameter to try |
[b] | * |
the error message |
Example
Two ways to use if. Either with one parameter:
var myHost = undef;
or with two parameters:
var myUndefined = undef;// Exeption raised above
*
undef.child(a, b, c, [d]) ⇒ Three parameters mode If a[b] is undefined, return c else a[b] Four parameters mode If a[b] is undefined, return d else c
Kind: static method of ifnotundef
Returns: *
- a[b] or c or d depending on their undefined status
Param | Type | Description |
---|---|---|
a | * |
the object |
b | * |
the child path |
c | * |
the first value |
[d] | * |
the second value |
Example
Two ways to use child. Either with three parameters (a[b]||c):
var myHost = undef;
or with four parameters (a[b]?c:d):
var myHost = undef;