18 - Class Type Checks
by steen_hansen
HTML
<!DOCTYPE html><meta charset="utf-8" />
<title>18 Class Type Checks</title>
<div id='js-div' style="width:51%; " >
<a href='https://github.com/steenhansen/type-czech' target="_blank" class='git-hub'>GitHub Package</a>
<div id='js-code'>the javascript</div>
</div>
<div id="the-explanation" style="width:49%" >
<div class='an-explantion'>18 - Class Type Checks</div>
<div id='explanation-text'>
<br>
When confirming class types, two checks are sometimes needed to ensure an
object is viable as methods can be accidentally deleted.
<br><br>
The object should be first checked for a valid type, to make sure the
expected prototype methods are there.
<pre>
type_czech.checkParam_type(class_variable, "the-class-name")
</pre>
Then, the object's interface should be checked just in case a needed method
no longer resides in the object. In the example to the left, the showPerson() method is deleted. Checking the
objects type doesn't reveal any issues. But the missing method is caught
by the below call.
<pre>
type_czech.check_interface(a_person, PERSON_INTERFACE)
</pre>
Note that the Person Class must be declared before the below linking code, or
a reference error is generated stating
"can't access lexical declaration 'Person' before initialization"
<pre>
/**/ Person = type_czech.linkUp(Person, undefined, POST_check_Person)
</pre>
</div>
<div id="console-log" >
<div class='a-title'>Console Output</div>
<div id='log-text'></div>
<br>
</div>
<br><br>
<!-- ----------------TYPE 1-------------------------- -->
<script src="https://cdn.jsdelivr.net/gh/steenhansen/type-czech@latest/web-resources/consolelog.js"></script>
<script src="https://cdn.jsdelivr.net/gh/steenhansen/type-czech@latest/web-resources/TypeCzech.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/steenhansen/type-czech@latest/web-resources/type-czech.css">
<!-- -------------TYPE...