10 - Class Parameters, Results, and Methods

by steen_hansen

HTML

<!DOCTYPE html><meta charset="utf-8" />
<title>10 Class Parameters, Results, and Methods</title>





<div id='js-div' style="width:49%">
  <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:51%">
 
  <div class='an-explantion'>10 - Class Parameters, Results, and Methods</div>
  <div id='explanation-text'>
    <br>

    Classes with multiple PRE and POST checking functions must be wrapped up in 
    objects like below for everything to be linked up.
<pre title='Copy and paste the green code below into the console to run' class='console-runnable'>
function PRE_check_yourClass(init){console.log('PRE class-', init)}
function POST_check_yourClass(result){console.log('POST class-', result)}
function PRE_check_yourMethod(input){console.log('PRE method-', input)}
function POST_check_yourMethod(output){console.log('POST method-', output)}

PRE_checks_class = { yourClass:PRE_check_yourClass,
                     yourMethod:PRE_check_yourMethod }
POST_check_class = { yourClass:POST_check_yourClass,
                     yourMethod:POST_check_yourMethod }

class yourClass {
  constructor(init_class){ this.init_class = init_class}
  yourMethod(method_input){ 
    return  this.init_class + ' ' + method_input
  }
}

yourClass = type_czech.linkUp(yourClass, PRE_checks_class, POST_check_class)
a_class = new yourClass('hello')
a_class.yourMethod('again')
</pre>
<pre>
>> PRE class- hello
>> POST class- Object { init_class: "hello", yourMethod: Proxy }
>> PRE method- again
>> POST method- hello again
>> "hello again"
</pre> 
Note that the type_czech.linkUp() call must come after the class declaration, otherwise
you get the below ReferenceError, because classes do not hoist functions.
<pre>
can't access lexical declaration 'yourClass' before initialization
</pre>



  </div>

  <div id="console-log"  >
    <div class='a-title'>Console...