Top Banner
SOLID JAVASCRIPT CODING MAY 24, 2015 - DIWA DEL MUNDO / VOYAGER INNOVATIONS
23
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Solid JavaScript Coding

S O L I D J AVA S C R I P T

C O D I N GM A Y 2 4 , 2 0 1 5 - D I W A D E L M U N D O / V O YA G E R I N N O VA T I O N S

Page 2: Solid JavaScript Coding

JavaScript is …

Page 3: Solid JavaScript Coding

– C H A R L E S J O S E P H U Y

“swiss army knife romance.”

JavaScript is …

Page 4: Solid JavaScript Coding

– M A . C Z A R I N A S . B O N G AT

“is a cool scripting language but hard to learn.”

JavaScript is …

Page 5: Solid JavaScript Coding

– S A M U E L F R A N C I S C O

“the language to rule them all.”

JavaScript is …

Page 6: Solid JavaScript Coding

- S E T A B A S E S TA N D A R D F O R J AVA S C R I P T D E V E L O P M E N T

W H Y A R E W E H E R E ?

- F O S T E R A C O L L A B O R AT I V E E N V I R O N M E N T F O R J AVA S C R I P T K N O W L E D G E L E A R N I N G

- G E T T O G E T H E R A N D H AV E L U N C H !

Page 7: Solid JavaScript Coding

O V E R V I E W O F T O D AY ’ S S E S S I O N

• JavaScript Review - Diwa del Mundo

• Object-Oriented Programming in JS - Zander Magtipon

• JavaScript Anti-Patterns - Russell Santos

• JS Race Conditions - Arisa Ochavez

• ECMAScript 6 - Ruel Pagayon

Page 8: Solid JavaScript Coding

git clone https://goo.gl/fNA4Ex

// If you have nvm: nvm use v0.12

node

Page 9: Solid JavaScript Coding

J AVA S C R I P T R E V I E W

• Variables, Globals

• Functions (Scopes, Constructor Functions, Self-executing)

• Object Literals and the “new” operator

• Closures

Page 10: Solid JavaScript Coding

1 . VA R I A B L E S . J S

• Primitives

• typeof

Page 11: Solid JavaScript Coding

2 . O B J E C T-L I T E R A L S . J S

• You can create variables either by literals or built-in constructors

• Object literals: key-value notation

• For non-custom objects, you’ll use literals most of the time

Page 12: Solid JavaScript Coding

3 . VA R S -G L O B A L S . J S

• Variables are declared via ‘var’, optional but recommended

• Not using ‘var’ makes your variable an implied global

• Implied globals can be deleted, explicit globals cannot be deleted

Page 13: Solid JavaScript Coding

4 . N O T E S - O N - T H I S . J S

• The variable ‘this’ inside a non-constructor function points to the global object

global

Page 14: Solid JavaScript Coding

5 . H O I S T I N G . J S

• Hoisting refers to the ‘jump to top’ behaviour of the JavaScript interpreter

• Interpreter “preprocesses” code

Page 15: Solid JavaScript Coding

6 . F U N C T I O N S . J S

• Functions are 1st-class objects in JS: they have properties and methods

• They provide scope

• Created dynamically, assigned, copied by reference

• Can be passed as arguments to other functions

• Types: function declarations, functional expression, named functional expression

Page 16: Solid JavaScript Coding

I M M E D I AT E F U N C T I O N S A N D C U R R Y I N G

• Immediate functions executes immediately - good for initialisation

• Currying - partial application of functions - good when calling functions with similar arguments

Page 17: Solid JavaScript Coding

N E W

Page 18: Solid JavaScript Coding

7 . C O N S T R U C T O R -F U N C T I O N S . J S

• You can create object instances using the ‘new’ operator

• “Objects” are defined via constructor functions

• ‘this’ refers to the instance

Page 19: Solid JavaScript Coding

http://www.thehindu.com/multimedia/dynamic/00846/20SM_VIJAY_846767f.jpg

Page 20: Solid JavaScript Coding

– C H A P T E R 3 , E X P E R T J AVA S C R I P T ( D A G G E T T )

A closure is the act of binding all free variables and functions into a closed expression that persist

beyond the lexical scope from which they were created.

Page 21: Solid JavaScript Coding

8 . C L O S U R E S . J S

• Most basic definition: an outer function that returns an inner function

• A way to have access to variables and functions that it shouldn’t have

Page 22: Solid JavaScript Coding

S U M M A R Y

• Use literals.

• Define objects through constructor functions.

• Understand ‘this’.

• Learn functions by heart.

• Whatever happens, make sure you know closures.

Page 23: Solid JavaScript Coding

Colophon

The animal in the photo in this presentation is a Tarsier.

References

See References.md JavaScript Patterns Expert JavaScript