Is there a way to catch typos when writing CoffeeScript

久未见 提交于 2019-12-05 01:15:54

问题


This small CoffeeScript contains a typo

drinks = "Coffee"
drinks = drinks + ", " + "Tea"
drinsk = drinks + ", " + "Lemonade"
alert drinks

The intention was to alert "Coffee, Tea, Lemonade" but the result is instead "Coffee, Tea". The generated JavaScript is still valid and passes JSLint; it declares the variables before usage which is good, but its the wrong variables.

var drinks, drinsk;
drinks = "Coffee";
drinks = drinks + ", " + "Tea";
drinsk = drinks + ", " + "Lemonade";
alert(drinks);

If the same example was written in plain JavaScript then JSLint would catch the error:

var drinks;
drinks = "Coffee";
drinks = drinks + ", " + "Tea";
drinsk = drinks + ", " + "Lemonade";
alert(drinks);

------------------
Problem at line 4 character 1: 'drinsk' was used before it was defined.
drinsk = drinks + ", " + "Lemonade";

To the question: Is there a way to keep the errors I make so that I can find them? I would love to see tools like JSLint still work.

Also tried http://www.coffeelint.org/ and it tells me "Your code is lint free!"


回答1:


You can use IDE which supports identifier spellchecking, for example, IntelliJ IDEA which BTW has a plugin for CoffeScript editing.




回答2:


I'd solve this by writing specs for your JavaScript. Lint type tools are great, but there are still plenty of other mistakes you can make.

Personally I use jasmine via jasmine-headless-webkit for this



来源:https://stackoverflow.com/questions/9835697/is-there-a-way-to-catch-typos-when-writing-coffeescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!