title: How to turn closure from old js library into typescript class?
body: <p>Hello I'm trying to convert JS library into TypeScript.
  Link to library: <a href="https://github.com/msarhan/hijrah-date" rel="nofollow noreferrer">https://github.com/msarhan/hijrah-date</a>
  I found it difficult to convert main function into class. I don't understand the part that why <code>HijrahDate</code> has a <code>HijrahDate</code> function in it ? Is it old way of creating constructor ?
  What I'm trying to achieve is to convert (if possible) old JS code into Typescript class.</p>
  <p>Simplified version</p>
  <pre class="lang-js prettyprint-override"><code>var HijrahDate = (function(){
  
    HijrahDate.isValid = isValid;
    HijrahDate.isHijrahDate = isHijrahDate;
  
    HijrahDate.prototype.getTime = getTime;
    HijrahDate.prototype.setFullYear = setFullYear;
  
    …
    init();
  
    function HijrahDate(year, monthOfYear, dayOfMonth, hours, minutes, seconds, milliseconds){
      this._year = Number.NaN;
      this._monthOfYear = Number.NaN;
      this._dayOfMonth = Number.NaN;
  
      var y, m, d, g;
      …
    }
  
    …
    function init(){
      var years = [];
      years['1300']=[30,29,30,29,30,29,30,29,30,29,30,29];
      … //rest of years till years['1600']
      var minYear = 1300;
      var maxYear = 1600;
      var isoStart = epochDayFromGregorain(new Date(1882, 11-1, 12));
      hijrahStartEpochMonth = minYear * 12;
      minEpochDay = isoStart;
      hijrahEpochMonthStartDays = createEpochMonths(minEpochDay, minYear, maxYear, years);
      maxEpochDay = hijrahEpochMonthStartDays[hijrahEpochMonthStartDays.length - 1];
  
      minYearLength = 0, maxYearLength = 0;
      for (var year = minYear; year &lt; maxYear; year++) {
          var length = _getYearLength(year);
          minYearLength = Math.min(minYearLength, length);
          maxYearLength = Math.max(maxYearLength, length);
      }
      …
    }
    return HijrahDate;
  
  })();
  ...
  </code></pre>
  <p>I've tried so far to create a class with contructor which has init inside</p>
  <pre class="lang-js prettyprint-override"><code>export class HijrahDate {
      year: number;
      monthOfYear: number;
      dayOfMonth: number;
      hours?: number;
      minutes?: number;
      private _gregorianDate: any;
      private _monthOfYear: any;
      private _dayOfMonth: any;
      seconds?: number;
      milliseconds?: number;
  
      constructor(
          year: number,
          monthOfYear: number,
          dayOfMonth: number,
          hours?: number,
          minutes?: number,
          seconds?: number,
          milliseconds?: number
      ) {
          this.year = year;
          this.monthOfYear = monthOfYear;
          this.dayOfMonth = dayOfMonth;
          this.hours = hours;
          this.minutes = minutes;
          this.seconds = seconds;
          this.milliseconds = milliseconds;
          this._gregorianDate = new Date();
          this.init();
      }
  </code></pre>