great_developer_habits
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| great_developer_habits [2019/11/01 15:42] – admin | great_developer_habits [2021/05/16 15:21] (current) – admin | ||
|---|---|---|---|
| Line 11: | Line 11: | ||
| - **Write code comment:** Explain "why this code is written" | - **Write code comment:** Explain "why this code is written" | ||
| - **Do Code Review** | - **Do Code Review** | ||
| + | |||
| + | |||
| + | ### A Template of code document | ||
| + | < | ||
| + | - Summary | ||
| + | - How to use it in the code | ||
| + | - Discussion | ||
| + | </ | ||
| Line 16: | Line 24: | ||
| - WWDC 2019 Great Developer Habbits: https:// | - WWDC 2019 Great Developer Habbits: https:// | ||
| </ | </ | ||
| + | |||
| + | |||
| + | ### Minimizing Function Footprint | ||
| + | |||
| + | It's good practice when writing plugins to only take up one slot within $.fn. This reduces both the chance that your plugin will be overridden, and the chance that your plugin will override other plugins. In other words, this is bad: | ||
| + | ```javascript | ||
| + | (function( $ ) { | ||
| + | |||
| + | $.fn.openPopup = function() { | ||
| + | // Open popup code. | ||
| + | }; | ||
| + | |||
| + | $.fn.closePopup = function() { | ||
| + | // Close popup code. | ||
| + | }; | ||
| + | |||
| + | }( jQuery )); | ||
| + | ``` | ||
| + | |||
| + | It would be much better to have one slot, and use parameters to control what action that one slot performs. | ||
| + | |||
| + | ```javascript | ||
| + | (function( $ ) { | ||
| + | |||
| + | $.fn.popup = function( action ) { | ||
| + | |||
| + | if ( action === " | ||
| + | // Open popup code. | ||
| + | } | ||
| + | |||
| + | if ( action === " | ||
| + | // Close popup code. | ||
| + | } | ||
| + | |||
| + | }; | ||
| + | |||
| + | }( jQuery )); | ||
| + | ``` | ||
great_developer_habits.1572594164.txt.gz · Last modified: (external edit)
