ES6 Arrow function vs Anonymous function with bind vs Anonymous with saved context vs pre-defined function with bind

Edit on GitHub

ES6 Arrow function vs Anonymous function with bind vs Anonymous with saved context vs pre-defined function with bind

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;
      });
    }
  • pre-defined function with bind

    var test = function(){
      let result = i * this.value;
    }
    
    for(let i=0; i<1000; i++) {
      test.bind(this);
    }