简体   繁体   English

函数调用中的javascript内联注释

[英]javascript inline comment inside function call

So I am having this document: 所以我有这个文件:

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    </head>
    <body>
        <script type="text/javascript">
            $(document).ready(function() {
                //executes when HTML-Document is loaded and DOM is ready
                alert("document is ready");
            });

            $(window).on("load", function () {
                //executes when HTML-Document is loaded and DOM is ready
                alert("window is loaded");
            });
        </script>
    </body>
</html>

Note the inline comments inside the 2 function calls. 注意两个函数调用中的内联注释。

Apparently these do NOT work and give me an error: 显然这些不起作用,给我一个错误:

SyntaxError: missing } after function body[Weitere Informationen] index:1:297 note: { opened at line 1, column 37

However using a multiline comment /* */ is working just perfectly. 但是,使用多行注释/* */可以完美地工作。 I`m assuming, that the single line comments dont work becuase somehow the javascript gets minified into one line. 我假设单行注释不起作用,因为以某种方式将javascript缩小为一行。 Can sombody evaluate an how this is happening? 某人可以评估情况如何吗? Where can you use single line comments and where not? 在哪里可以使用单行注释? Or is it just generally a bad idea to use single line comments in js? 还是在js中使用单行注释通常不是一个好主意吗?

因为缩小所有内容后仅一行,所以没有注释结束标记的一行注释不起作用。

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

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