7

I got easily confused by jQuery's coding style. So many brackets, incline functions and nests in nests. How can I change my coding style to improve this? Any great examples to show this??

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
lkahtz
  • 4,706
  • 8
  • 46
  • 72

3 Answers3

7

Check out the excellent jQuery coding standards series here:

Sarfraz
  • 377,238
  • 77
  • 533
  • 578
2

CoffeeScript is a little language that compiles into JavaScript. Underneath all of those embarrassing braces and semicolons, JavaScript has always had a gorgeous object model at its heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.

I haven't try it out yet , but I think it is a good way ....

wizztjh
  • 6,979
  • 6
  • 58
  • 92
0

One thing is application architecture and patterns, another your actual coding style / convention. E.g. jQuery Coding Style Guide. It can bring also some questions.

Just use http://jscodesniffer.dsheiko.com/ online or https://github.com/dsheiko/jscodesniffer binary script to check how valid the source code is from the prospective of jQuery Coding Style Guide.

The style seems simple in general but makes one wander when meeting exception cases like:

Liberal spacing on function arguments

  • If inside other function call, no spaces wrapping the expression allowed otherwise grouping parens must have one padding space
  • Functions, object literals, array literals and string literals go snug to front and back of the parentheses when it's the only argument
  • Multi-line function/object/array literals go snug at end

While checking code with the sniffer regularly (e.g. via svn/git pre-commit hook) you are getting used to the rules.

Dmitry Sheiko
  • 2,130
  • 1
  • 25
  • 28