Last Updated: 29 Oct 2023
|
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
front-end-tech:javascript:best-practices [Aug 24, 2010 06:44 AM] dordal |
front-end-tech:javascript:best-practices [Oct 29, 2023 03:42 PM] 114.119.132.88 old revision restored (Nov 21, 2020 10:39 PM) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | = JavaScript Notes & Best Practices = | ||
+ | These are a few notes and best practices for doing client-side development with Javascript. | ||
+ | |||
+ | === Use a JavaScript Library === | ||
+ | |||
+ | First and foremost, you'll almost certainly want to use a JavaScript library. Like CSS, JavaScript isn't entirely cross-browser compatible, and there are a number of things that are harder to do than they should be. A JS library eases your pain on both these fronts, while (typically) adding very little overhead. My favorite library is [[http:// | ||
+ | === Namespace Your Code === | ||
+ | |||
+ | You'll probably want to put all of your JS code in a namespace. See [[Namespacing and Aliasing Namespaces In Javascript]] | ||
+ | |||
+ | === Return null, not false === | ||
+ | |||
+ | Since JavaScript supports '' | ||
+ | |||
+ | This is no different than any other language, but is still a mistake that is easy to make. | ||
+ | |||
+ | === Using Optional Parameters & Default Arguments === | ||
+ | |||
+ | If you need to create a function with optional parameters and defaults for those parameters that aren't specified, see [[Optional Parameters & Default Arguments]]. | ||
+ | |||
+ | === Using Classes & the ' | ||
+ | |||
+ | Since classes are [[Basic JavaScript# | ||
+ | === Unobtrusive Javascript === | ||
+ | |||
+ | If possible, it is a good idea to write ' | ||
+ | |||
+ | === Progressive Enhancement === | ||
+ | |||
+ | The idea behind progressive enhancement is to create a page that any browser can read, but then progressively ' |