How to structure my javascript/jquery code?

前端 未结 10 936
我寻月下人不归
我寻月下人不归 2020-12-12 09:22

I am toying around with a pretty intensive ajax based jquery web application. It is getting to a point where I almost loose track of what events that should trigger what act

10条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 10:21

    My js files usually follow a naming convention similar to this :

    • xxx.utility.js
    • mypage.events.js
    • xxx.common.js
    • /lib/
    • /OS-DoNotDistribute/lib/

    Where

    • 'mypage' is the name of the html, aspx, php, etc file.
    • 'xxx' is the concept. (i.e. orders.common.js)
    • 'utility' signifies it's a reusable library script (i.e. ajax.utility.js, controlfader.utility.js)
    • 'common' is reusable functionality for this app, but not reusable across other projects
    • 'lib' is a subdirectory for any external or library scripts
    • 'OS-DoNotDistribute' is a subdirectory to ensure no OS licensed code is distributed if the app is ever sold.

    Also, for ajax, I have a special naming convention for call back functions, so it's easy to tell what they are.

    I'm not sure it that's close to what you were looking for, but I hope it helps.

提交回复
热议问题