JavaScript 中的 main() 函数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8629859/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
main() function in JavaScript?
提问by Isuru
I have seen a main()
function in some JavaScript files I have come across. Is it the same main function as you use in other languages such as C#, C++?? If you put a main function in your JS file, is that where the code starts executing? Or is it just another name used for a function?
我main()
在我遇到的一些 JavaScript 文件中看到了一个函数。它是否与您在其他语言(如 C#、C++)中使用的 main 函数相同??如果你在你的 JS 文件中放了一个 main 函数,那是代码开始执行的地方吗?或者它只是用于函数的另一个名称?
I have searched the web but didn't find anything useful regarding this matter.
我在网上搜索过,但没有找到任何关于此事的有用信息。
回答by FishBasketGordo
No, main
is not the same in JavaScript as in C languages. It's just another function, but the original programmer is probably using the name as a convention to indicate where the code shouldstart running.
不,main
在 JavaScript 中与在 C 语言中不同。这只是另一个函数,但最初的程序员可能使用该名称作为约定来指示代码应该从哪里开始运行。
回答by Alon Adler
"Main" function has nothing different then any other function (Its just a name). It will run when called and not automatically.
“Main”函数与任何其他函数没有什么不同(它只是一个名称)。它将在调用时运行,而不是自动运行。
回答by Riccardo Galli
It is just a name given to a function, there isn't such a thing as C "main" in javascript.
它只是一个函数的名字,在javascript中没有C“main”这样的东西。