JavaScript中代碼組織的廣泛接受的最佳實踐[關閉]

問題:

As JavaScript frameworks like jQuery make client side web applications richer and more functional, I've started to notice one problem... 隨着像jQuery這樣的JavaScript框架使客戶端Web應用程序更豐富,更實用,我開始注意到一個問題...... web

How in the world do you keep this organized? 你是如何保持這種組織的? app

  • Put all your handlers in one spot and write functions for all the events? 將全部處理程序放在一個位置併爲全部事件編寫函數?
  • Create function/classes to wrap all your functionality? 建立函數/類來包裝全部功能?
  • Write like crazy and just hope it works out for the best? 寫得像瘋了似的,只但願它能作到最好?
  • Give up and get a new career? 放棄並得到新的職業?

I mention jQuery, but it's really any JavaScript code in general. 我提到了jQuery,但它其實是任何JavaScript代碼。 I'm finding that as lines upon lines begin to pile up, it gets harder to manage the script files or find what you are looking for. 我發現隨着線條開始堆積起來,管理腳本文件或找到你要找的東西變得更加困難。 Quite possibly the biggest propblems I've found is there are so many ways to do the same thing, it's hard to know which one is the current commonly accepted best practice. 我發現最大的問題多是有不少方法能夠作一樣的事情,很難知道哪個是目前廣泛接受的最佳實踐。 框架

Are there any general recommendations on the best way to keep your .js files as nice and neat as the rest of your application? 是否有關於保持.js文件與應用程序其他部分同樣美觀和整潔的最佳方法的通常建議? Or is this just a matter of IDE? 或者這僅僅是IDE的問題? Is there a better option out there? 那裏有更好的選擇嗎? ide


EDIT 編輯 函數

This question was intended to be more about code organization and not file organization. 這個問題旨在更多地關注代碼組織而不是文件組織。 There has been some really good examples of merging files or splitting content around. 有一些很是好的合併文件或分割內容的例子。 ui

My question is: what is the current commonly accepted best practice way to organize your actual code? 個人問題是:目前廣泛接受的組織實際代碼的最佳實踐方法是什麼? What is your way, or even a recommended way to interact with page elements and create reuseable code that doesn't conflict with each other? 您的方式是什麼,甚至是推薦的方式與頁面元素交互並建立不會相互衝突的可重用代碼? this

Some people have listed namespaces which is a good idea. 有些人列出了名稱空間 ,這是一個好主意。 What are some other ways, more specifically dealing with elements on the page and keeping the code organized and neat? 還有什麼其餘方法,更具體地說是處理頁面上的元素並保持代碼整潔有序? idea


解決方案:

參考一: https://stackoom.com/question/12JF/JavaScript中代碼組織的廣泛接受的最佳實踐-關閉
參考二: https://oldbug.net/q/12JF/Commonly-accepted-best-practices-around-code-organization-in-JavaScript-closed
相關文章
相關標籤/搜索