Is it possible to format JavaScript / JQuery code using strings and tabs?

As a C # encoder learning JavaScript, I find this 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. But I do not understand why. Will it bother me anywhere?

Update: You can set the indent value at the bottom of the jslint page and thereby make your code "valid". There is a JsLint plug, http://www.jshint.com/ , which also accepts tabs.

+5
source share
4 answers

A warning from JSLint is a matter of taste. The one who wrote it discovers that ordering things this way makes sense:

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

, , , , .

, , , - ( jslint) , .

+1

jsLint : 4 ,

( , - , )

+3

, , jslint (, , , $ , )

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

, ,

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

if(something)
{
   // do something
}
else
{
   //do something else
}

You should always use indentation, and this is good coding practice.

0
source

All Articles