SlideShare a Scribd company logo
JAVASCRIPT DEVELOPMENT DONE RIGHT 
CONFITURA 2014 
Created by 
Paweł Szulc 
/ / 
http://rabbitonweb.com @paulszulc paul.szulc@gmail.com 
var microphone = { 
testing: function(oneTwoThree) { 
console.log("testing, testing " + oneTwoThree); 
} 
}
PEACEFUL JAVA 
Understandable object oriented language 
Vast and rich ecosystem of frameworks, tools and 
technologies 
Static code analysis, well-known conventions and best 
practices 
Testable, clean and readable code
Javascript development done right
Javascript development done right
MORDOR SCRIPT
JAVASCRIPT 
Strange, bizarre and non deterministic language 
Coding like its 1996 all over again 
Not a single unit test, no static code analysis
Javascript development done right
$ GIT CLONE GIT://GITHUB.COM/YOU/YOUR-PROJECT. 
GIT
Javascript development done right
JAVA VS JAVASCRIPT
“JAVASCRIPT IS 
TO JAVA AS 
HAMBURGER IS 
TO HAM.”
KEY DIFFERENCES 
Language nature: object vs functional 
Different concepts (e.g function vs method, scope definitions) 
Different set of operators and key words (===, undefined) 
Different nature of operators and key words (e.g this)
IMPORTANT 
“TO USE THE LANGUAGE 
PROPERLY, UNDERLYING 
CONCEPTS UNDERSTAND YOU 
MUST”
FUNCTIONS
FUNCTIONS ARE FIRST CLASS CITIZENS 
They can be assigned to variables, arrays and properties of 
other objects 
They can be passed as arguments to functions 
They can be returned as values from functions 
The only difference between a function and an object, is that 
functions can be invoked
EXAMPLES 
function () { 
} 
// ? 
function problemSolver() { 
} 
problemSolver(); 
problemSolver("I have a problem, please do solve it"); 
function problemSolver(problem, hint) { 
} 
problemSolver(problem, hint); 
problemSolver(problem); 
problemSolver(); 
problemSolver(problem, hint, "some other parameter out of nowhere"); 
function problemSolver(problem, hint) { 
return 42; 
}
THIS
THIS 
THE THIS PARAMETER REFERS TO AN OBJECT 
THAT’S IMPLICITLY ASSOCIATED WITH THE 
FUNCTION INVOCATION.
THIS = CONTEXT
THIS = CONTEXT
Javascript development done right
IF IT QUACKS LIKE A DUCK, IT MUST BE A ... 
var duck = {}; 
duck.name = "Donald Duck"; 
var dog = {}; 
dog.name = "Pluto"; 
duck.say = function() { 
console.log("Quack quack, call me " + this.name); 
} dog.say = function() { 
console.log("Bark bark, call me " + this.name); 
} 
duck.say(); 
dog.say(); 
Quack quack, call me Donald Duck 
Bark bark, call me Pluto 
duck.say.call(dog); 
Quack quack, call me Pluto
WHAT THE QUACK? 
duck.say = function() { 
console.log("Quack quack, call me " + this.name); 
} dog.say = function() { 
console.log("Bark bark, call me " + this.name); 
} 
duck.say.call(dog); 
Quack quack, call me Pluto
FUNCTION INVOCATION 
THERE ARE FOUR DIFFERENT WAYS FOR 
FUNCTION TO BE INVOKED 
1. as function 
2. as method 
3. as constructor 
4. by apply() or call()
AS FUNCTION 
function timestamp() { 
this.stamp = new Date(); 
}; 
timestamp(); 
console.log(window.stamp) 
Fri Apr 11 2014 01:56:07 GMT+0200 (Central European Daylight Time)
AS METHOD 
var problemSolver = {}; 
problemSolver.timestamp = function() { 
this.stamp = new Date(); 
}; 
problemSolver.timestamp(); 
console.log(problemSolver.stamp) 
Fri Apr 11 2014 01:56:07 GMT+0200 (Central European Daylight Time)
AS CONSTRUCTOR 
function person(name) { 
this.name = name; 
return this; 
}; 
var p1 = new person('Captain Bomba'); 
console.log(p1.name) 
Captain Bomba
BY APPLY() OR CALL() 
var duck = {}; 
duck.name = "Donald Duck"; 
var dog = {}; 
dog.name = "Pluto"; 
duck.say = function() { 
console.log("Quack quack, call me " + this.name); 
} dog.say = function() { 
console.log("Bark bark, call me " + this.name); 
} 
duck.say.call(dog); 
Quack quack, call me Pluto
SCOPE EXTRAVAGANZA
IN MOST C-LIKE LANGUAGES BLOCK CREATES 
A SCOPE 
// java 
if(true) { 
Engine engine = new Engine(); 
} engine.start(); // compilation error
IN JAVASCRIPT FUNCTION CREATES A SCOPE 
function pkp(where) { 
if(where === 'Szczecin') { 
var announcment = 'Sorry, taki mamy klimat'; 
} 
return announcment; // ok, in scope 
} assert(announcment === undefined); // out of scope
JAVASCRIPT KILLER 
var a = 1; 
function b() { 
a = 10; 
return; 
function a() {} 
} b(); 
console.log(a); // ?
HOISTING 
FUNCTION DECLARATIONS AND VARIABLE DECLARATIONS ARE 
ALWAYS MOVED (“HOISTED”) INVISIBLY TO THE TOP OF THEIR 
CONTAINING SCOPE BY THE JAVASCRIPT INTERPRETER. 
function foo() { 
bar(); 
var x = 1; 
function bar() { } 
} 
function foo() { 
function bar() { } 
var x; 
bar(); 
x = 1; 
}
HOISTING 
function foo() { 
bar(); // exception! 
var bar = function() {} 
} 
function foo() { 
var bar; 
bar(); 
bar = function() { } 
}
CLOSURES 
function outer() { 
var name = "Bob"; 
function inner() { 
return "Somewhere out there, there's a guy called " + name; 
} 
console.log(inner()); 
} 
outer(); 
Somewhere out there, there's a guy called Bob
CLOSURES 
function outer() { 
var name = "Bob"; 
function inner() { 
return "Somewhere out there, there's a guy called " + name; 
} 
return inner; 
} 
var ref = outer(); 
console.log(ref()); 
Somewhere out there, there's a guy called Bob
OBJECTS 
Everything is an object (even function) 
No such thing as class 
Everything is a map
OBJECTS 
var person = {}; 
var person = {}; 
person.name = "John"; 
person.eat = function(food) { ... }; 
var person = {}; 
person["name"] = "John"; 
person["eat"] = function(food) { ... }; 
var person = { 
name: "John", 
eat: function(food) { ... }; 
};
MODULES
THERE IS NO SUCH THING 
AS 'PRIVATE'
MODULES 
CLOSURE TO THE RESCUE! 
var JDBC = (function() { 
function connection() { ... } 
function runSQL(sql) { 
var c = connection(); 
c.execute(sql); 
} 
return { 
runSQL: runSQL 
}; 
})();
TOOLS 
Testing: Jasmine, Mocha, much much more... 
Static code analysis: JSLint 
Dependency injection: require.js
THE END 
BY PAWEŁ SZULC / RABBITONWEB.COM 
email: paul.szulc@gmailcom / twitter: @paulszulc

More Related Content

PDF
Expression trees in c#
PPTX
Expression trees in c#, Алексей Голубь (Svitla Systems)
PDF
Introduction to Functional Programming
PDF
JavaScript - new features in ECMAScript 6
PDF
ES2015 (ES6) Overview
PDF
EcmaScript 6 - The future is here
PPTX
ES6: Features + Rails
ODP
Ast transformations
Expression trees in c#
Expression trees in c#, Алексей Голубь (Svitla Systems)
Introduction to Functional Programming
JavaScript - new features in ECMAScript 6
ES2015 (ES6) Overview
EcmaScript 6 - The future is here
ES6: Features + Rails
Ast transformations

What's hot (20)

PDF
Python postgre sql a wonderful wedding
PPTX
Nice to meet Kotlin
PPTX
Introduction to Ecmascript - ES6
ODP
AST Transformations
PDF
はじめてのGroovy
PPTX
Visualizing ORACLE performance data with R @ #C16LV
PDF
"PostgreSQL and Python" Lightning Talk @EuroPython2014
PPTX
Building native Android applications with Mirah and Pindah
PDF
Clojurian Conquest
PPT
Ggug spock
KEY
Alfresco the clojure way
ZIP
Oral presentation v2
PDF
Kotlin Bytecode Generation and Runtime Performance
PDF
Groovy ネタ NGK 忘年会2009 ライトニングトーク
PDF
Android dev toolbox - Shem Magnezi, WeWork
PPTX
2015 555 kharchenko_ppt
PDF
Lambdas and Streams Master Class Part 2
PDF
GoCracow #5 Bartlomiej klimczak - GoBDD
PDF
What's in Kotlin for us - Alexandre Greschon, MyHeritage
PDF
Do you Promise?
Python postgre sql a wonderful wedding
Nice to meet Kotlin
Introduction to Ecmascript - ES6
AST Transformations
はじめてのGroovy
Visualizing ORACLE performance data with R @ #C16LV
"PostgreSQL and Python" Lightning Talk @EuroPython2014
Building native Android applications with Mirah and Pindah
Clojurian Conquest
Ggug spock
Alfresco the clojure way
Oral presentation v2
Kotlin Bytecode Generation and Runtime Performance
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Android dev toolbox - Shem Magnezi, WeWork
2015 555 kharchenko_ppt
Lambdas and Streams Master Class Part 2
GoCracow #5 Bartlomiej klimczak - GoBDD
What's in Kotlin for us - Alexandre Greschon, MyHeritage
Do you Promise?
Ad

Viewers also liked (20)

PPT
19th March Session 2 By Anuradha Das Mathur
PDF
Emprender en la Actualidad - JECA 2015 Universidad Nacional del Sur
PPTX
Salut!
PDF
Informe de gestión
PPT
D:\Introduccion A Sql 2000 Server
PDF
Cuentos 2008 De Cristian Carcamo
DOCX
Cuál es mi idea
DOCX
Data recovery
PDF
La ética y la moral
DOC
Análisis Fílmico
PDF
RESUMEN DE MUELLE Y LOS SALTAPIEDRA, POR IZAN SÁNCHEZ 1º B
PPTX
Falsafah keperawatan
PPTX
Introduccion a SQL
PPTX
Taller de informatica_803_(2)
PPT
Презентація:Матеріали до уроків
DOCX
Joseph Gigliotti - Resume (Linked-In)
PDF
Estatuto del representante legal
PPTX
Wearables en la comunicación
DOCX
Planes y programas
DOC
Vocabulario dibujos
19th March Session 2 By Anuradha Das Mathur
Emprender en la Actualidad - JECA 2015 Universidad Nacional del Sur
Salut!
Informe de gestión
D:\Introduccion A Sql 2000 Server
Cuentos 2008 De Cristian Carcamo
Cuál es mi idea
Data recovery
La ética y la moral
Análisis Fílmico
RESUMEN DE MUELLE Y LOS SALTAPIEDRA, POR IZAN SÁNCHEZ 1º B
Falsafah keperawatan
Introduccion a SQL
Taller de informatica_803_(2)
Презентація:Матеріали до уроків
Joseph Gigliotti - Resume (Linked-In)
Estatuto del representante legal
Wearables en la comunicación
Planes y programas
Vocabulario dibujos
Ad

Similar to Javascript development done right (20)

PPTX
Ian 20150116 java script oop
DOC
Jsphp 110312161301-phpapp02
PPTX
5 Tips for Better JavaScript
PDF
JavaScript for PHP developers
PDF
JavaScript Survival Guide
PPTX
Kotlin For Android - Functions (part 3 of 7)
PDF
The Future of JVM Languages
PPSX
What's New In C# 7
PDF
No excuses, switch to kotlin
PPTX
JavaScript - i och utanför webbläsaren (2010-03-03)
PDF
Presentatie - Introductie in Groovy
PDF
Swift Study #7
PDF
CoffeeScript
ODP
AST Transformations at JFokus
KEY
Javascript tid-bits
PDF
Discover Dart(lang) - Meetup 07/12/2016
ODP
Groovy Ast Transformations (greach)
PDF
Easily mockingdependenciesinc++ 2
PDF
Discover Dart - Meetup 15/02/2017
Ian 20150116 java script oop
Jsphp 110312161301-phpapp02
5 Tips for Better JavaScript
JavaScript for PHP developers
JavaScript Survival Guide
Kotlin For Android - Functions (part 3 of 7)
The Future of JVM Languages
What's New In C# 7
No excuses, switch to kotlin
JavaScript - i och utanför webbläsaren (2010-03-03)
Presentatie - Introductie in Groovy
Swift Study #7
CoffeeScript
AST Transformations at JFokus
Javascript tid-bits
Discover Dart(lang) - Meetup 07/12/2016
Groovy Ast Transformations (greach)
Easily mockingdependenciesinc++ 2
Discover Dart - Meetup 15/02/2017

More from Pawel Szulc (20)

PDF
Getting acquainted with Lens
PDF
Impossibility
PDF
Maintainable Software Architecture in Haskell (with Polysemy)
PDF
Painless Haskell
PDF
Trip with monads
PDF
Trip with monads
PDF
Illogical engineers
PDF
RChain - Understanding Distributed Calculi
PDF
Illogical engineers
PDF
Understanding distributed calculi in Haskell
PDF
Software engineering the genesis
PDF
Make your programs Free
PDF
Going bananas with recursion schemes for fixed point data types
PDF
“Going bananas with recursion schemes for fixed point data types”
PDF
Writing your own RDD for fun and profit
PDF
The cats toolbox a quick tour of some basic typeclasses
PDF
Introduction to type classes
PDF
Functional Programming & Event Sourcing - a pair made in heaven
PDF
Apache spark workshop
PDF
Introduction to type classes in 30 min
Getting acquainted with Lens
Impossibility
Maintainable Software Architecture in Haskell (with Polysemy)
Painless Haskell
Trip with monads
Trip with monads
Illogical engineers
RChain - Understanding Distributed Calculi
Illogical engineers
Understanding distributed calculi in Haskell
Software engineering the genesis
Make your programs Free
Going bananas with recursion schemes for fixed point data types
“Going bananas with recursion schemes for fixed point data types”
Writing your own RDD for fun and profit
The cats toolbox a quick tour of some basic typeclasses
Introduction to type classes
Functional Programming & Event Sourcing - a pair made in heaven
Apache spark workshop
Introduction to type classes in 30 min

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Spectroscopy.pptx food analysis technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
Teaching material agriculture food technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Programs and apps: productivity, graphics, security and other tools
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Cloud computing and distributed systems.
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MYSQL Presentation for SQL database connectivity
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Building Integrated photovoltaic BIPV_UPV.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Chapter 3 Spatial Domain Image Processing.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Network Security Unit 5.pdf for BCA BBA.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectral efficient network and resource selection model in 5G networks
Spectroscopy.pptx food analysis technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Teaching material agriculture food technology
Review of recent advances in non-invasive hemoglobin estimation
Programs and apps: productivity, graphics, security and other tools
“AI and Expert System Decision Support & Business Intelligence Systems”
Cloud computing and distributed systems.
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

Javascript development done right

  • 1. JAVASCRIPT DEVELOPMENT DONE RIGHT CONFITURA 2014 Created by Paweł Szulc / / http://rabbitonweb.com @paulszulc [email protected] var microphone = { testing: function(oneTwoThree) { console.log("testing, testing " + oneTwoThree); } }
  • 2. PEACEFUL JAVA Understandable object oriented language Vast and rich ecosystem of frameworks, tools and technologies Static code analysis, well-known conventions and best practices Testable, clean and readable code
  • 6. JAVASCRIPT Strange, bizarre and non deterministic language Coding like its 1996 all over again Not a single unit test, no static code analysis
  • 8. $ GIT CLONE GIT://GITHUB.COM/YOU/YOUR-PROJECT. GIT
  • 11. “JAVASCRIPT IS TO JAVA AS HAMBURGER IS TO HAM.”
  • 12. KEY DIFFERENCES Language nature: object vs functional Different concepts (e.g function vs method, scope definitions) Different set of operators and key words (===, undefined) Different nature of operators and key words (e.g this)
  • 13. IMPORTANT “TO USE THE LANGUAGE PROPERLY, UNDERLYING CONCEPTS UNDERSTAND YOU MUST”
  • 15. FUNCTIONS ARE FIRST CLASS CITIZENS They can be assigned to variables, arrays and properties of other objects They can be passed as arguments to functions They can be returned as values from functions The only difference between a function and an object, is that functions can be invoked
  • 16. EXAMPLES function () { } // ? function problemSolver() { } problemSolver(); problemSolver("I have a problem, please do solve it"); function problemSolver(problem, hint) { } problemSolver(problem, hint); problemSolver(problem); problemSolver(); problemSolver(problem, hint, "some other parameter out of nowhere"); function problemSolver(problem, hint) { return 42; }
  • 17. THIS
  • 18. THIS THE THIS PARAMETER REFERS TO AN OBJECT THAT’S IMPLICITLY ASSOCIATED WITH THE FUNCTION INVOCATION.
  • 22. IF IT QUACKS LIKE A DUCK, IT MUST BE A ... var duck = {}; duck.name = "Donald Duck"; var dog = {}; dog.name = "Pluto"; duck.say = function() { console.log("Quack quack, call me " + this.name); } dog.say = function() { console.log("Bark bark, call me " + this.name); } duck.say(); dog.say(); Quack quack, call me Donald Duck Bark bark, call me Pluto duck.say.call(dog); Quack quack, call me Pluto
  • 23. WHAT THE QUACK? duck.say = function() { console.log("Quack quack, call me " + this.name); } dog.say = function() { console.log("Bark bark, call me " + this.name); } duck.say.call(dog); Quack quack, call me Pluto
  • 24. FUNCTION INVOCATION THERE ARE FOUR DIFFERENT WAYS FOR FUNCTION TO BE INVOKED 1. as function 2. as method 3. as constructor 4. by apply() or call()
  • 25. AS FUNCTION function timestamp() { this.stamp = new Date(); }; timestamp(); console.log(window.stamp) Fri Apr 11 2014 01:56:07 GMT+0200 (Central European Daylight Time)
  • 26. AS METHOD var problemSolver = {}; problemSolver.timestamp = function() { this.stamp = new Date(); }; problemSolver.timestamp(); console.log(problemSolver.stamp) Fri Apr 11 2014 01:56:07 GMT+0200 (Central European Daylight Time)
  • 27. AS CONSTRUCTOR function person(name) { this.name = name; return this; }; var p1 = new person('Captain Bomba'); console.log(p1.name) Captain Bomba
  • 28. BY APPLY() OR CALL() var duck = {}; duck.name = "Donald Duck"; var dog = {}; dog.name = "Pluto"; duck.say = function() { console.log("Quack quack, call me " + this.name); } dog.say = function() { console.log("Bark bark, call me " + this.name); } duck.say.call(dog); Quack quack, call me Pluto
  • 30. IN MOST C-LIKE LANGUAGES BLOCK CREATES A SCOPE // java if(true) { Engine engine = new Engine(); } engine.start(); // compilation error
  • 31. IN JAVASCRIPT FUNCTION CREATES A SCOPE function pkp(where) { if(where === 'Szczecin') { var announcment = 'Sorry, taki mamy klimat'; } return announcment; // ok, in scope } assert(announcment === undefined); // out of scope
  • 32. JAVASCRIPT KILLER var a = 1; function b() { a = 10; return; function a() {} } b(); console.log(a); // ?
  • 33. HOISTING FUNCTION DECLARATIONS AND VARIABLE DECLARATIONS ARE ALWAYS MOVED (“HOISTED”) INVISIBLY TO THE TOP OF THEIR CONTAINING SCOPE BY THE JAVASCRIPT INTERPRETER. function foo() { bar(); var x = 1; function bar() { } } function foo() { function bar() { } var x; bar(); x = 1; }
  • 34. HOISTING function foo() { bar(); // exception! var bar = function() {} } function foo() { var bar; bar(); bar = function() { } }
  • 35. CLOSURES function outer() { var name = "Bob"; function inner() { return "Somewhere out there, there's a guy called " + name; } console.log(inner()); } outer(); Somewhere out there, there's a guy called Bob
  • 36. CLOSURES function outer() { var name = "Bob"; function inner() { return "Somewhere out there, there's a guy called " + name; } return inner; } var ref = outer(); console.log(ref()); Somewhere out there, there's a guy called Bob
  • 37. OBJECTS Everything is an object (even function) No such thing as class Everything is a map
  • 38. OBJECTS var person = {}; var person = {}; person.name = "John"; person.eat = function(food) { ... }; var person = {}; person["name"] = "John"; person["eat"] = function(food) { ... }; var person = { name: "John", eat: function(food) { ... }; };
  • 40. THERE IS NO SUCH THING AS 'PRIVATE'
  • 41. MODULES CLOSURE TO THE RESCUE! var JDBC = (function() { function connection() { ... } function runSQL(sql) { var c = connection(); c.execute(sql); } return { runSQL: runSQL }; })();
  • 42. TOOLS Testing: Jasmine, Mocha, much much more... Static code analysis: JSLint Dependency injection: require.js
  • 43. THE END BY PAWEŁ SZULC / RABBITONWEB.COM email: paul.szulc@gmailcom / twitter: @paulszulc