JavaScript with no if’s

No if’s.Only buts ? Enter dbj.cond(). Stright into the deep end.

var x = dbj.cond(v1,v2,v3,v4,v5,v6)

Is a shorthand for:

 

Original dbj.cond() , worked only on values that can be compared
for equality, with native ‘===’ operator.

New dbj.cond() allows users to compare values for equality with other values of any type or arrays of them. Syntax is the same as before:

There can be any number of pairs before last argument and after the first argument.

Behaviour is that arguments can be of any type including objects, arrays, dates, etc. Function compare(a,b) is called comparator.

Comparator is any function which receives two arguments and returns true or
false as a result of comparing the arguments. Simple comparator example:

examples

Order is “first found, first served”. Any types can be compared meaningfully. For example:
This behavior allows for functions dispatching. Example:
Comparator is user definable. dbj.cond() is using comparator function assigned to:
Please see online qUnit Tests, for further examples.Internals

  • Comparator in essence defines the behaviour of dbj.cond()
  • Default inbuilt comparator works for all types.
  • First argument of the dbj.cond() is the left side in the comparison.
    Second value can be single value or array.
  • Default comparator allows for arrays of values to be compared with the single input value of the same type
  • Examples:
  • First argument of the comparator is also called “input”
  • Heart of complex comparator for dbj.cond(), is originaly made by Philippe Rathé
  • Tests for equality of any JavaScript type. Used in QUnit.
  • Discussions and reference: http://philrathe.com/articles/equiv
Standard Comparator
Standard Comparator