title: JS same function different parameters in every object value. How can I write less?
body: <p><strong>What I did</strong></p>
  <p>I call a function in objects' value.</p>
  <p>And this function would be called in every object as much as users add an <code>absent</code> data.</p>
  <p><strong>What I want to do</strong></p>
  <p>Hence I recognize that I could have thousands of hundred of new object, I would rather minimize/eliminate duplication than write the function every time.</p>
  <p><strong>Explain what the code is for</strong></p>
  <p>The function's name I would like to auto-set is <code>datesBetween()</code>.</p>
  <p><code>datesBetween()</code> can choose the mode, and it has parameters.</p>
  <p>The mode refers the value from the key <code>reason</code> which is in same object. <code>arr[0].absent[0].datesBetween</code>'s value should be <code>datesBetween('leave')('2020-1-1','2020-1-4')</code>.</p>
  <p>The parameters does same. First parameter should refer from the object key <code>start</code> which is in same object, second parameter should refer from the object key <code>end</code>.</p>
  <p><strong>Some idea</strong></p>
  <ol>
  <li>I guess this could use <code>class</code> but I am afraid to mix up with functions. if class would help, please do tell.</li>
  <li>I write <code>this</code> thou, I am uncertain about <code>this</code>. Is using <code>this</code> could be a solution in this code?
  <div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var arr = [
    {
      name : "A", 
      absent :[ 
        {
          reason : "leave",
          start : '2020-1-1',
          end : '2020-1-4',
          datesBetween : datesBetween('leave')(this.start, this.end)
        }, {
          reason : "sleeOver",
          start : '2020-1-25',
          end : '2020-1-26',
          datesBetween : datesBetween('sleeOver')(this.start, this.end)
        }    
      ]
    }, {
      name : "B", 
      absent :[
        {
          reason : "weekendExcursion",
          start : '2020-1-18',
          end : '2020-1-19',
          datesBetween : datesBetween('weekendExcursion')(this.start, this.end)
        }
      ]
    }  
  ]
  
  function autoAbsentSetter(){
    //do I need class to use inheritance/property things?
    
  }
  
  function addAbsent(mode){
    var funcs = {
      'leave' : function absent_leave(name, absentName, absentStart, absentEnd){ //all kinds of leave are included. Detail further.
      //some codes
      },
      'sleepOver' : function absent_sleepOver(name, absentName, absentStart, absentEnd){
      //some codes
      },
      'weekdayExcursion' : function absent_weekdayExcursion(name, absentName, absentStart, absentEnd){
      //some codes
      },
      'weekendExcursion' : function absent_weekendExcursion(name, absentName, absentStart, absentEnd){
      //some codes
      }
    }
    return funcs[mode];
  }</code></pre>
  </div>
  </div>
  </li>
  </ol>