title: TypeScript class function as function VS variable which has better performace
body: <p><strong>Is it better using variables which define a function or using a function in the first place?
  Furthermore, is there a difference for tree-shaking?</strong></p>
  <p>I have a lot of calculation (static) intensive helper classes and was wondering what the best (memory/speed) is.</p>
  <p>Here the different ways I have in mind:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>class MyClass {
    readonly functionA = (v: string | number, maxDeep: number, curDeep: number = 0): string =&gt; {
        if (curDeep &lt; maxDeep) {
            return this.functionA(v, maxDeep, curDeep + 1);
        } else {
            return "function A" + v;
        }
    }
  
    static functionB(v: string | number, maxDeep: number, curDeep: number = 0): string {
        if (curDeep &lt; maxDeep) {
            return MyClass.functionB(v, maxDeep, curDeep + 1);
        } else {
            return "function B" + v;
        }
    }
  
    functionC(v: string | number, maxDeep: number, curDeep: number = 0): string {
        if (curDeep &lt; maxDeep) {
            return this.functionC(v, maxDeep, curDeep + 1);
        } else {
            return "function C" + v;
        }
    }
  
    static readonly functionD = (v: string | number, maxDeep: number, curDeep: number = 0): string =&gt; {
        if (curDeep &lt; maxDeep) {
            return MyClass.functionD(v, maxDeep, curDeep + 1);
        } else {
            return "function D" + v;
        }
    }
  }</code></pre>
  </div>
  </div>
  </p>
  <p>I tried using <a href="https://jsben.ch/JX0VR" rel="nofollow noreferrer">JSBen</a> for measuring a difference but the results seem to be random.
  <a href="https://i.stack.imgur.com/rc8Pw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rc8Pw.png" alt="enter image description here" /></a></p>