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;

Tests

  • 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++) {
      let t = function() {
        let result = i * this.value;
      }.bind(this);
      t();
    }
  • Anonymous with saved context

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