It seems to me that, in ES6, the following two functions are very nearly identical:
function () {
return this;
}.bind(this);
() => {
return this;
};
The end result seems the same: arrow functions produce a JavaScript function object with their this
context bound to the same value as the this
where they are created.
Obviously, in the general sense, Function.prototype.bind
is more flexible than arrow functions: it can bind to values other than the local this
, and it can bind any function's this
at any point in time, potentially long after it is initially created. However, I'm not asking how bind
itself is different from arrow functions, I'm asking how arrow functions differ from immediately calling bind
with this
.
Are there any differences between the two constructs in ES6?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…