简体   繁体   English

意外转译 ES6>ES5

[英]Unexpected Transpile ES6>ES5

When transpiling this function into ES5 from ES6 (using Babel) I didn't expect it to change当将此函数从 ES6 转译为 ES5 时(使用 Babel)我没想到它会改变

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 .在下面的代码段中,请注意我递归调用ff - 仅对该函数是本地的,而我使用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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM