Object structure can be checked with checkParam_type(). This code checks that the
properties of funcOne and funcTwo are both
functions. And the property a_number must be a Number type. Missing or
extra properties will cause errors.
FUNC_NUM_FUNC = { func1: 'function', a_num: 'number', an_str: 'string' }
pass_func_num_func = {func1: x=>x, a_num:12, an_str: 'passes-test'}
type_czech.checkParam_type(pass_func_num_func, FUNC_NUM_FUNC) // pass
fail_func_num_func = {a_string:'fails-test'}
type_czech.checkParam_type(fail_func_num_func, FUNC_NUM_FUNC) // fail
The below example shows how to ignore some properties, while still type checking
at least one property. Here we only ensure that the property funcOne is a
Function, the extra property my_string is ignored.
FUNC_ONE_ONLY = { funcOne: 'function'}
func_num_func_obj = {funcOne: x=>x, my_string:'passes-test'}
type_czech.checkParam_typeExtra(func_num_func_obj, FUNC_ONE_ONLY) // pass
fail_num_func_obj = {funcOne: 1, my_string:'fails-test'}
type_czech.checkParam_typeExtra(fail_num_func_obj, FUNC_ONE_ONLY) // fail
In the examples to the left, the first callMethod() function parameter, an_object, is checked to
see if it implements the showPerson() function, if not it fails the checkParam_type() call.