Upload
francisco-ferreira
View
1.289
Download
1
Tags:
Embed Size (px)
Citation preview
Javascriptfor multi disciplinary teams 101
Software Engineer at eBay
Francisco M.S. Ferreira
I present my own opinion and point of view, not the one of my employer.
Why use Java?
• Used everywhere (allegedly)
• Strongly typed language
• Compiled language
• Object Oriented
• Tons of available frameworks
Why use JavaScript?
• Used everywhere (allegedly)
• Strongly typed language
• Compiled language
• Object Oriented
• Tons of available frameworks
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!
Typical team
Typical team
Front End Back End
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.
Java class
Flexibility
Flexibility
My favorite
Private variables
Public functions
Fool proof
Tastes like Java
Step by step
Private variables
Public variables
Private functions
Public functions
Static variables
Static functions
Feels object oriented
No private statics
What about extensions?
What about extensions?
If JS was java…
Let’s apply
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!
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
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
Folder naming
Java packages
Folder naming
Java packages JavaScript folders
The three big walls of JS
•JavaScript is not type safe!
•JavaScript is single threaded!
•Lot’s of callbacks with closures!
Javascript !== TypeSafe
If you use:
===
!==
All these
would be
false
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
Single Threaded!
setTimeout
someOtherCode
moreCode
...
aCallback
Mountain of Doom
• Hard to reado And maintain
• Callback hell
• Issueso Memory Leaks
o Error prone
o Hard to debug
o Hard to test
Q & A