The intended manner for using TypeCzech is to
toggle
runtime checking by loading or not loading TypeCzech.js.
The below code will render all TypeCzech calls into no-ops when
TypeCzech.js is not loaded, virtually no cpu time is lost as
can be seen in /time-trials/time-differences.js.
if (typeof TypeCzech === 'function')
type_czech = TypeCzech('LOG-ERRORS')
else
type_czech = { linkUp: (nop) => nop, isActive: (x) => false }
Program with TypeCzech testing turned ON.
<script src="../web-resources/TypeCzech.js">
Program with TypeCzech testing turned OFF.
<!-- <script src="../web-resources/TypeCzech.js"> -->
By using the below construct,
non-existant PRE and POST checking functions
will just be ignored by TypeCzech. Useful for not including large blocks of
testing code to the browser that will be parsed. This style stops exceptions when non-existant checking functions are referenced.
PRE_check_aLottery = (typeof PRE_check_aLottery === 'undefined')
? undefined : PRE_check_aLottery
// function PRE_check_aLottery (){
// // this function is ignored if does not exist
// }
Best practice is to use both constructs to handle turning TypeCzech checking functions on and off.
-
if (typeof TypeCzech === 'function')
type_czech = TypeCzech('THROW-EXCEPTIONS')
else
type_czech = { linkUp: (nop) => nop, isActive: (x) => false }
-
PRE_check_func=(typeof PRE_check_func==='undefined') ? undefined : PRE_check_func