How can I organize the jQuery code style to avoid confusion by so many brackets and so many nests? Any good sample?

跟風遠走 提交于 2020-01-12 05:27:13

问题


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??


回答1:


Check out the excellent jQuery coding standards series here:

  • jQuery Coding Standards



回答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 ....




回答3:


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.



来源:https://stackoverflow.com/questions/4529804/how-can-i-organize-the-jquery-code-style-to-avoid-confusion-by-so-many-brackets

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