简体   繁体   English

编译器喜欢指出Javascript的错误

[英]Compiler like to point bugs for Javascript

I am somewhat of a beginner with JS but it occured to me that it would be nice to have a compiler like thingy that shows where the errors are (though its an interpreted language) - i am currently using Webstorm without any customizations but as far as i can tell its not pointing to obvious errors. 我有点像JS的初学者,但是对我来说,拥有一个像whaty这样的编译器来显示错误的位置(尽管它是一种解释语言)会很好-我目前正在使用Webstorm,但没有进行任何自定义,但是我可以告诉它没有指出明显的错误。 For example if i have an opening brace and not a closing brace; 例如,如果我有一个大括号而不是一个大括号; or an extra closing brace - a compiler would point to that fact; 或额外的括号-编译器将指出这一事实; i am sure JS has some eqivalent way - isnt there? 我确定JS有某种等效的方式-不是吗?

  <script>
        var switchDirection = false;

        function doAnimation(){
            var divAdvert = document.getElementById("divAdvert");
            var currentLeft = divAdvert.offsetLeft;
            var newLocation;

            if(!switchDirection) {
                newLocation = currentLeft + 2;

                if (currentLeft >= 400) {
                    switchDirection = true;
                }
            }else{
                    newLocation = currentLeft -2;

                    if(currentleft <=0){
                        switchDirection = false;
                    }
            }
                divAdvert.style.left = newLocation + "px";
        }
        }  // extra closing brace hard to find; why isnt there a compiler like thing to show where errors are for JS?

Here are some of your options: 以下是您的一些选择:

  • NodeJS; NodeJS; it's basically JavaScript for servers (rather than webpages), and can be run in a CLI environment, which will show you errors. 它基本上是用于服务器(而不是网页)的JavaScript,并且可以在CLI环境中运行,这会向您显示错误。
  • The browser console will spit out errors in your code when you try to run in. 当您尝试运行时,浏览器控制台将吐出代码中的错误。
  • Linters such as JSHint and JSLint will point out problems similar to browser consoles, and will also give you code style tips. 诸如JSHint和JSLint之类的Linter会指出类似于浏览器控制台的问题,并且还会为您提供代码样式提示。
  • IDE plugins. IDE插件。 I'm sure if an IDE doesn't come out of the box with support for things like this, you can find a plugin for it (try looking for an automatic linter plugin). 我确定如果IDE不支持此类功能,您可以为其找到一个插件(尝试寻找自动linter插件)。

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

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