When we declare a function, we are usually
var foo function (a) {
Console.log (a)
};
With ES6, we write this.
var foo = a =>{
Console.log (a);
};
Foo (2);
It's just less of a function field what's the redundancy thing?
First look at the following code:
var obj={
ID: "Love"
Love:functionlove () {
Console.log (this.id);
}
};
var id = "hit"
Obj.love (); Love
SetTimeout (obj.love,100); Love
All love, nothing wrong, it should be settimeout (obj.love,100); Enter hit
According to the analysis, the love function loses the binding between the same and this, should be hit this should be the window most commonly used is the var self = This, to handle the following this:
var obj = {
ID: "Not Love",
Love:function () {
var = this
Console.log (this.id);
}};
var id = "Not hit"
Obj.love ()
SetTimeout (Obj.love (), 1000);
Oh, the legendary fat-tipped. This binding behavior is completely inconsistent with normal function behavior, is it solved in es5? No, in strict mode, these are not problems, but in non-strict mode it will output hit
JS's Fat arrow problem