How can I style my jQuery code style to avoid confusion with multiple brackets and multiple nests? Any good sample?

I was easily confused by the jQuery coding style. So many brackets, slant functions, and sockets in sockets. How to change the coding style to improve this? Any great examples to show this?

+7
source share
3 answers

Check out the excellent jQuery coding standards series:

+7
source

CoffeeScript is a small language that compiles in JavaScript. Beneath all these embarrassing brackets and semicolons, JavaScript has always been a great object model at its heart. CoffeeScript is an attempt to show the good parts of JavaScript in a simple way.

I have not tried it yet, but I think this is a good way.

+2
source

One thing is architecture and application patterns, the other is your coding style / convention. For example. JQuery Coding Style Guide. This may also raise some questions.

Just use http://jscodesniffer.dsheiko.com/ online or https://github.com/dsheiko/jscodesniffer binary script to check how correct the source code is from the jQuery prospective style guide.

The style seems simple in general, but it wanders when exception cases occur, for example:

Liberal spacing for function arguments

  • If inside another function call there are no spaces in which the expression resolved otherwise is executed, the parser grouping must have one filling space
  • Functions, object literals, array literals, and string literals go to the front and back of parentheses when this is the only argument
  • Multi-line functions / objects / massive literals go at the end

Regularly checking the code using a sniffer (for example, using svn / git pre-commit hook), you get used to the rules.

0
source

All Articles