Writing quality JavaScript code. .pdf

File information


Original filename: Writing quality JavaScript code..pdf

This PDF 1.5 document has been generated by / Skia/PDF m64, and has been sent on pdf-archive.com on 07/11/2017 at 20:26, from IP address 131.251.x.x. The current document download page has been viewed 203 times.
File size: 113 KB (2 pages).
Privacy: public file


Download original PDF file


Writing quality JavaScript code..pdf (PDF, 113 KB)


Share on social networks



Link to this file download page



Document preview


Writing​ ​quality​ ​JavaScript.
Remember!​ ​It’s​ ​still​ ​object​ ​oriented!
Even​ ​though​ ​it’s​ ​a​ ​web​ ​language,​ ​JavaScript​ ​is​ ​still​ ​object​ ​oriented,​ ​even​ ​if​ ​there​ ​are
no​ ​classes.​ ​Always​ ​approach​ ​the​ ​problem​ ​in​ ​an​ ​object​ ​oriented​ ​fashion,​ ​always
remember​ ​to​ ​separate​ ​classes​ ​if​ ​necessary​ ​and​ ​don’t​ ​be​ ​afraid​ ​from​ ​using
Prototypes​ ​in​ ​your​ ​JavaScript​ ​in​ ​order​ ​to​ ​maintain​ ​the​ ​more​ ​reusable​ ​parts​ ​of​ ​code
and​ ​to​ ​create​ ​a​ ​hierarchy​ ​for​ ​your​ ​objects.​ ​This​ ​is​ ​especially​ ​useful​ ​when​ ​creating
web​ ​apps​ ​and​ ​will​ ​help​ ​you​ ​endlessly​ ​for​ ​both​ ​usability​ ​and​ ​maintainability,​ ​well
written​ ​objects​ ​and​ ​their​ ​children​ ​are​ ​the​ ​key​ ​to​ ​a​ ​smooth​ ​running​ ​and​ ​easily
maintainable​ ​codebase.
Remember​ ​your​ ​code​ ​conventions.
In​ ​JavaScript​ ​you​ ​will​ ​be​ ​doing​ ​the​ ​following​ ​in​ ​your​ ​code:
- Use​ ​camelCase,​ ​like​ ​you​ ​would​ ​be​ ​if​ ​you​ ​were​ ​coding​ ​in​ ​its​ ​non​ ​script
counterpart
- Constants​ ​that​ ​are​ ​declared​ ​will​ ​LOOK_LIKE_THIS
- The​ ​declaration​ ​of​ ​variables​ ​always​ ​starts​ ​with​ ​‘var’
- Always​ ​uses​ ​an​ ​explicit​ ​scope.
- There​ ​are​ ​no​ ​wrappers​ ​for​ ​the​ ​primitive​ ​objects!

Use​ ​global​ ​variables​ ​lightly!
In​ ​JavaScript​ ​the​ ​use​ ​of​ ​global​ ​variables​ ​is​ ​to​ ​be​ ​done​ ​lightly,​ ​for​ ​both​ ​readability​ ​and
security​ ​reasons,​ ​remember​ ​that​ ​global​ ​variables​ ​can​ ​be​ ​manipulated​ ​and​ ​gotten​ ​by
the​ ​user,​ ​which​ ​we’d​ ​rather​ ​keep​ ​under​ ​wraps​ ​if​ ​possible,​ ​it​ ​is​ ​also​ ​very​ ​easy​ ​when
writing​ ​javascript​ ​for​ ​the​ ​namespace​ ​to​ ​get​ ​incredibly​ ​clogged​ ​up,​ ​you​ ​could​ ​be
accidently​ ​using​ ​a​ ​different​ ​variable​ ​and​ ​not​ ​even​ ​know​ ​it,​ ​obviously​ ​creating​ ​a​ ​range
of​ ​problems​ ​when​ ​it​ ​comes​ ​to​ ​you​ ​debugging,​ ​you​ ​also​ ​have​ ​to​ ​think​ ​about​ ​the​ ​user,
javascript​ ​can​ ​also​ ​be​ ​compiled​ ​on​ ​for​ ​example​ ​phones,​ ​which​ ​have​ ​less​ ​memory
allocation​ ​space​ ​and​ ​saving​ ​global​ ​variables​ ​can​ ​be​ ​fairly​ ​costly​ ​over​ ​time,​ ​so​ ​best​ ​to
be​ ​safe​ ​and​ ​keep​ ​the​ ​scope​ ​of​ ​your​ ​variables​ ​as​ ​local​ ​as​ ​possible​ ​if​ ​you​ ​can​ ​help​ ​it.

Always​ ​return​ ​your​ ​functions​ ​as​ ​early​ ​as​ ​possible,​ ​keep​ ​it​ ​readable​ ​and
running​ ​as​ ​fast​ ​as​ ​possible!
Remember​ ​that​ ​your​ ​code​ ​should​ ​always​ ​flow,​ ​and​ ​when​ ​writing​ ​a​ ​function​ ​it​ ​should
look​ ​how​ ​the​ ​code​ ​will​ ​flow,​ ​it​ ​is​ ​a​ ​script​ ​after​ ​all,​ ​but​ ​also​ ​remember​ ​that​ ​if​ ​you​ ​can
exit​ ​out​ ​of​ ​a​ ​large​ ​function,​ ​why​ ​not​ ​do​ ​so​ ​at​ ​the​ ​first​ ​possible​ ​opportunity?​ ​While
avoiding​ ​long​ ​lines​ ​of​ ​Else​ ​if​ ​statements.

To​ ​illustrate​ ​this​ ​look​ ​at​ ​the​ ​code​ ​below.

It​ ​waits​ ​till​ ​the​ ​end​ ​to​ ​throw​ ​the​ ​error​ ​and​ ​also​ ​enters​ ​into​ ​a​ ​new​ ​code​ ​block,​ ​however
if​ ​we​ ​rearrange​ ​this​ ​a​ ​little​ ​we​ ​can​ ​make​ ​it​ ​return​ ​faster.

Look​ ​how​ ​it​ ​now​ ​exits​ ​out​ ​at​ ​the​ ​first​ ​check,​ ​before​ ​anything​ ​is​ ​attempted​ ​the​ ​first
check​ ​is​ ​done​ ​and​ ​then​ ​code​ ​block​ ​can​ ​exit​ ​before​ ​trying​ ​to​ ​execute​ ​code​ ​that​ ​might
just​ ​slow​ ​it​ ​down.

Bibliography 
C2(2010),​ ​Global​ ​variables​ ​are​ ​bad​ ​-​ ​http://wiki.c2.com/?GlobalVariablesAreBad 
 
Medium(2012),​ ​5​ ​ ​Tips​ ​for​ ​more​ ​maintainable​ ​JavaScript​ ​- 
https://medium.com/functionite-speaks-javascript/5-tips-for-writing-more-ma
intainable-javascript-code-b87de1147e94  
 
 


Document preview Writing quality JavaScript code..pdf - page 1/2

Document preview Writing quality JavaScript code..pdf - page 2/2

Related documents


writing quality javascript code
rubyprogramminglanguage
eloquent javascript 1
paper 1
paper
psychlonic way of the shadow

Link to this page


Permanent link

Use the permanent link to the download page to share your document on Facebook, Twitter, LinkedIn, or directly with a contact by e-Mail, Messenger, Whatsapp, Line..

Short link

Use the short link to share your document on Twitter or by text message (SMS)

HTML Code

Copy the following HTML code to share your document on a Website or Blog

QR Code

QR Code link to PDF file Writing quality JavaScript code..pdf