Can you bind 'this' in an arrow function?

前端 未结 11 2302
囚心锁ツ
囚心锁ツ 2020-11-22 03:09

I\'ve been experimenting with ES6 for a while now, and I\'ve just come to a slight problem.

I really like using arrow functions, and whenever I can, I use them.

11条回答
  •  灰色年华
    2020-11-22 03:31

    To be complete, you can re-bind arrow functions, you just can't change the meaning of this.

    bind still has value for function arguments:

    ((a, b, c) => {
      console.info(a, b, c) // 1, 2, 3
    }).bind(undefined, 1, 2, 3)()
    

    Try it here: http://jsbin.com/motihanopi/edit?js,console

提交回复
热议问题