07 - Mutated Function Parameters
by steen_hansen
HTML
<!DOCTYPE html><meta charset="utf-8" />
<title>07 Mutated Function Parameters</title>
<div id='js-div' style="width: 60%">
<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:40%" class='code-scroll'>
<div class='an-explantion'>07 - Mutated Function Parameters</div>
<div id='explanation-text'>
<br>
Objects and Arrays can be guarded from mutations in function calls with
check_buildSnapshot() recording the entry value, and check_mutatedSnapshot() giving errors
when referential variables get unwanted changes.
<br><br>
Checking for variable mutation is accomplished by first creating a
snapshot copy of the object or array in the PRE checking function with
check_buildSnapshot(). In the example to the left, the function name
of 'PRE_check_Person' is recorded, along with the variable name of 'a_person',
followed finally with the current variable value.
<br><br>
The POST checking function then verifies that no changes have occured
in the varaible via check_mutatedSnapshot(). The orginating function and
variable name are needed to locate the specific object or array that is being
checked.
<br><br>
It can be somewhat disconcerting to view the error messages as object keys
are sorted for easy comparing.
<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 1------------------------ -->
<div id='js-fiddles'>
...