js for multidisciplinary teams

36
Javascript for multi disciplinary teams 101

Upload: francisco-ferreira

Post on 15-Jul-2015

1.289 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: JS for multidisciplinary teams

Javascriptfor multi disciplinary teams 101

Page 2: JS for multidisciplinary teams

Software Engineer at eBay

Francisco M.S. Ferreira

I present my own opinion and point of view, not the one of my employer.

Page 3: JS for multidisciplinary teams

Why use Java?

• Used everywhere (allegedly)

• Strongly typed language

• Compiled language

• Object Oriented

• Tons of available frameworks

Page 4: JS for multidisciplinary teams

Why use JavaScript?

• Used everywhere (allegedly)

• Strongly typed language

• Compiled language

• Object Oriented

• Tons of available frameworks

Page 5: JS for multidisciplinary teams

Why use JavaScript?

• Used everywhere (allegedly)

• Strongly typed language

• Compiled language

• Object Oriented

• Tons of available frameworks

• Extremely flexible

• It is what runs on the browser!

Page 6: JS for multidisciplinary teams

Typical team

Page 7: JS for multidisciplinary teams

Typical team

Front End Back End

Page 8: JS for multidisciplinary teams

What to expect

• An intro to JavaScripto Simulate Object-Oriented JavaScript

• Packaging / Folder structure

• Known walls new developers hit

o Type safety

o Single threaded system

o Mountain/Piramid of doom.

Page 9: JS for multidisciplinary teams

Java class

Page 10: JS for multidisciplinary teams

Flexibility

Page 11: JS for multidisciplinary teams

Flexibility

Page 12: JS for multidisciplinary teams

My favorite

Private variables

Public functions

Fool proof

Page 13: JS for multidisciplinary teams

Tastes like Java

Page 14: JS for multidisciplinary teams

Step by step

Page 15: JS for multidisciplinary teams

Private variables

Page 16: JS for multidisciplinary teams

Public variables

Page 17: JS for multidisciplinary teams

Private functions

Page 18: JS for multidisciplinary teams

Public functions

Page 19: JS for multidisciplinary teams

Static variables

Page 20: JS for multidisciplinary teams

Static functions

Page 21: JS for multidisciplinary teams

Feels object oriented

No private statics

Page 22: JS for multidisciplinary teams

What about extensions?

Page 23: JS for multidisciplinary teams

What about extensions?

Page 24: JS for multidisciplinary teams

If JS was java…

Page 25: JS for multidisciplinary teams

Let’s apply

Page 26: JS for multidisciplinary teams

What happened there

• When calling apply or call:o The this scope is shared between functions

o Allows multiple inheritances

o Allows order of execution in inheritances

o Directly inherits!

Page 27: JS for multidisciplinary teams

What happened there

• When calling apply or call:o The this scope is shared between functions

o Allows multiple inheritances

o Allows order of execution in inheritances

o Directly inherits!

• It only shares:o ‘public’ functions and variables

Page 28: JS for multidisciplinary teams

What happened there

• When calling apply or call:o The this scope is shared between functions

o Allows multiple inheritances

o Allows order of execution in inheritances

o Directly inherits!

• It only shares:o ‘public’ functions and variables

• It may overwrite methods or get overwritten

Page 29: JS for multidisciplinary teams

Folder naming

Java packages

Page 30: JS for multidisciplinary teams

Folder naming

Java packages JavaScript folders

Page 31: JS for multidisciplinary teams

The three big walls of JS

•JavaScript is not type safe!

•JavaScript is single threaded!

•Lot’s of callbacks with closures!

Page 32: JS for multidisciplinary teams

Javascript !== TypeSafe

If you use:

===

!==

All these

would be

false

Page 33: JS for multidisciplinary teams

Equality of objects is deep

• Recursively compare all elements

• If order is guaranteed:o JSON.stringify && compare JSONs

• Use deep compare function ≈ 120 lines of codeo http://stackoverflow.com/questions/1068834/object-comparison-in-javascript

Page 34: JS for multidisciplinary teams

Single Threaded!

setTimeout

someOtherCode

moreCode

...

aCallback

Page 35: JS for multidisciplinary teams

Mountain of Doom

• Hard to reado And maintain

• Callback hell

• Issueso Memory Leaks

o Error prone

o Hard to debug

o Hard to test

Page 36: JS for multidisciplinary teams

Q & A