When transpiling this function into ES5 from ES6 (using Babel) I didn't expect it to change
var func = function(msg){
alert(msg);
}
but it became
var func = function func(msg) {
alert(msg);
};
Why is this and how does it affect usage of the function, if at all? Even if it doesn't affect usage, is there anything I should know? Thank you.
It doesn't affect the usage of the function as well, but it does give the function a way to reference itself.
In the following snippet, notice that I recursively call ff
-- which is local only to that function, while I invoke it using func
.
The upshot is: It's harmless, and you can ignore it.
var func = function ff(t) { if (t === 0) { console.log("Countdown down"); } else { console.log("Counting down", t); ff(t - 1); } }; func(10);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.