title: Lambda functions vs bind, memory! (and performance)
body: <p>I would like to determine which is the best practice between equivalent solutions. The use case is an instance of a class that listen to an event. Dr. Axel Rauschmayer <a href="http://www.2ality.com/2016/02/arrow-functions-vs-bind.html" rel="noreferrer">prefers the lambda</a> for readability. I agree with him. But in term of performance and memory consumption, which is the best?</p>
  
  <h1>With a lambda function</h1>
  
  <pre><code>class Abc {
    constructor() {
      let el = document.getElementById("my-btn")
      if (el)
        el.addEventListener("click", evt =&gt; this.onClick(evt))
    }
    onClick(evt) {
      console.log("Clicked!", evt.target)
    }
  }
  </code></pre>
  
  <p>Can someone to confirm or infirm if the local variables (here <code>el</code>) can't be cleared by the garbage collector? Or, are modern browsers capable to detect they are unused in the closure?</p>
  
  <h1>With <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind" rel="noreferrer"><code>Function.prototype.bind</code></a>:</h1>
  
  <pre><code>class Abc {
    constructor() {
      let el = document.getElementById("my-btn")
      if (el)
        el.addEventListener("click", this.onClick.bind(this))
    }
    onClick(evt) {
      console.log("Clicked!", evt.target)
    }
  }
  </code></pre>
  
  <p>There is no memory issue, but all benchmarks suggest that <code>bind</code> is far slower than a closure (an example <a href="https://jsperf.com/bind-vs-closure-setup/32" rel="noreferrer">here</a>).</p>
  
  <p><em>EDIT: I don't agree with the comments that ignore the performance issue of <code>bind</code>. I suggest to read <a href="https://stackoverflow.com/a/17638540/3786294">this answer</a> with the code of the implementation in Chrome. It cannot be efficient. And I insist: <strong>all</strong> the benchmarks I saw, show similar results on <strong>all</strong> browsers.</em></p>
  
  <p>Is there a way to have a low memory usage and a good performance at the same time?</p>