ES6 Arrow function vs Anonymous function with bind vs Anonymous with saved context

Edit on GitHub

Arrow function vs. anonymous function with bind vs. anonymous with saved context

Setup

this.value = 1.5;

let self = this;

Tests

  • ES6 Arrow function

    for(let i=0; i<1000; i++) {
      () => {
        let result = i * this.value;
      }
    }
  • Anonymous function with bind

    for(let i=0; i<1000; i++) {
      (function() {
        let result = i * this.value;
      }).bind(this);
    }
  • Anonymous with saved context

    for(let i=0; i<1000; i++) {
      (function() {
        let result = i * self.value;
      });
    }