Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I format my JavaScript/JQuery code with linebreaks and tabs?

As a c# coder learning JavaScript I find this alot more readable:

$(this)
  .first()
  .prepend("<h3>Title</h3>")
  .end()
  .removeClass("hidden");

than this:

$(this).first().prepend("<h3>Title</h3>").end().removeClass("hidden");

However JSLint complains about the first one. But I don´t understand why. Will this get me into trouble anywhere?

Update: You can set the value of indentation at the bottom of the jslint page and thereby make your code "valid". There is a fork of JsLint, http://www.jshint.com/, that accepts tabs as well.

like image 681
Mikael Härsjö Avatar asked Oct 09 '22 14:10

Mikael Härsjö


1 Answers

The issue with that code on jsLint is due to the identation: if you indent it with 4 spaces there're no errors

(scroll down to the options and change identation settings if default value is not what you want)

like image 72
Fabrizio Calderan Avatar answered Oct 12 '22 10:10

Fabrizio Calderan