[英]What happens behind the scenes with this Javascript code?
(()=>{
console.log("Hello, world");
})();
此功能如何工作? 似乎很模糊,我想逐步了解一下实际发生的情况。
这是ECMAScript6。它使用=>
(称为“箭头”或“胖箭头”)运算符创建一个匿名函数。 该函数执行console.log("Hello, world");
执行时。 然后,您发布的代码将执行该功能(尾随();
)。
它像这样分解:
( // wrapper for the function definition
()=>{ // use => to create an anonymous function
console.log("Hello, world"); // body of the function
} // end of the function definition
) // end of the wrapper for the function definition
(); // executes the function.
您可以在我发布的先前答案中或在Mozilla文档中阅读有关箭头功能的更多信息。
它将消息输出到Web控制台。 这是带有完整API的页面的链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.