SlideShare a Scribd company logo
1 of 36
Download to read offline
/**
* southWest
* Gets the southwestern quadrant of the tree
* return {Quadtree}
**/
Quadtree.prototype.southWest = function() {
return new Quadtree(
new space2d.Point(
this._origin.x,
Math.floor(this._size.y / 2)
),
new space2d.Point(
Math.floor(this._size.x / 2),
this._size.y
),
this
);
};
/**
* southEast
* Gets the southeastern quadrant of the tree
* return {Quadtree}
**/
Quadtree.prototype.southEast = function() {
return new Quadtree(
new space2d.Point(
Math.floor(this._size.x / 2),
Math.floor(this._size.y / 2)
),
new space2d.Point(
this._size.x,
this._size.y
),
this
);
};
JavaScript
What they don’t tell you about
Raphael Cruzeiro
http://raphaelcruzeiro.com
@rcdeveloper
Wednesday, July 10, 13
What does JavaScript have in
common with Java?
Wednesday, July 10, 13
What does JavaScript have in
common with Java?
The first four letters of its name.
Wednesday, July 10, 13
It actually
has a lot more in common with
Python
and other dynamic and
functional languages
Wednesday, July 10, 13
Originally named
LiveScript
Wednesday, July 10, 13
It was created by Netscape to
enhance web pages.
Wednesday, July 10, 13
It is used today not only in
the browser but also to
create desktop widgets and
server-side code.
Wednesday, July 10, 13
Formalized in ECMAScript.
Wednesday, July 10, 13
“The problem with JavaScript is that nobody
tries to learn it before writing applications
with it.” - Douglas Crockford
Wednesday, July 10, 13
JavaScript
makes it
easy
to write
terrible code.
Wednesday, July 10, 13
var currentId;
var lastViewPort;
var precision = Math.pow(10, 4);
var maxPointNumber = 100;
var circleOverlays = [];
function didViewPortChange() {
var minLat = lastViewPort.getSouthWest().lat() -
(lastViewPort.getNorthEast().lat() - lastViewPort.getSouthWest().lat());
var minLng = lastViewPort.getSouthWest().lng() -
(lastViewPort.getNorthEast().lng() - lastViewPort.getSouthWest().lng());
var maxLat = lastViewPort.getNorthEast().lat() +
(lastViewPort.getNorthEast().lat() - lastViewPort.getSouthWest().lat());
var maxLng = lastViewPort.getNorthEast().lng() +
(lastViewPort.getNorthEast().lng() - lastViewPort.getSouthWest().lng());
if ($.fn.jqMap.getMap().getBounds().getNorthEast().lat() > maxLat ||
$.fn.jqMap.getMap().getBounds().getNorthEast().lng() > maxLng ||
$.fn.jqMap.getMap().getBounds().getSouthWest().lat() < minLat ||
$.fn.jqMap.getMap().getBounds().getSouthWest().lng() < minLng) {
return true;
}
else {
return false;
}
}
Really bad code:
Wednesday, July 10, 13
var currentId;
var lastViewPort;
var precision = Math.pow(10, 4);
var maxPointNumber = 100;
var circleOverlays = [];
function didViewPortChange() {
var minLat = lastViewPort.getSouthWest().lat() -
(lastViewPort.getNorthEast().lat() - lastViewPort.getSouthWest().lat());
var minLng = lastViewPort.getSouthWest().lng() -
(lastViewPort.getNorthEast().lng() - lastViewPort.getSouthWest().lng());
var maxLat = lastViewPort.getNorthEast().lat() +
(lastViewPort.getNorthEast().lat() - lastViewPort.getSouthWest().lat());
var maxLng = lastViewPort.getNorthEast().lng() +
(lastViewPort.getNorthEast().lng() - lastViewPort.getSouthWest().lng());
if ($.fn.jqMap.getMap().getBounds().getNorthEast().lat() > maxLat ||
$.fn.jqMap.getMap().getBounds().getNorthEast().lng() > maxLng ||
$.fn.jqMap.getMap().getBounds().getSouthWest().lat() < minLat ||
$.fn.jqMap.getMap().getBounds().getSouthWest().lng() < minLng) {
return true;
}
else {
return false;
}
}
Really bad code:
GUILTY
Wednesday, July 10, 13
Global scope polluting
Wednesday, July 10, 13
var something = 4;
Wednesday, July 10, 13
When declaring variables on
the global scope you make
your code more susceptible to
name clashes.
Wednesday, July 10, 13
In JavaScript a function
delimits the scope of
variables
Wednesday, July 10, 13
var something = 4;
function foo () {
somethingElse = something + 4;
return somethingElse;
};
foo();
Accidental use of global
variables
Wednesday, July 10, 13
Dangers of
Hoisting
Wednesday, July 10, 13
var something = 4;
var somethingElse = 7;
function foo () {
console.log(something);
console.log(somethingElse);
var something = “This is confusing.”;
console.log(something);
};
foo();
Wednesday, July 10, 13
var something = 4;
var somethingElse = 7;
function foo () {
console.log(something);
console.log(somethingElse);
var something = “This is confusing.”;
console.log(something);
};
foo();
Outputs:
undefined
7
This is confusing.
Wednesday, July 10, 13
Objects
with no
classes
Wednesday, July 10, 13
Pretty much
everything
is an object in
JavaScript
Wednesday, July 10, 13
With a few exceptions:
•Number
•String
•Boolean
•null
•undefined
Wednesday, July 10, 13
A side-note about Numbers:
•There is only one type for representing all
numbers.
•It is represented in memory as a 64-bit
floating point
•IEEE-754
> 0.1 + 0.2
0.30000000000000004
Wednesday, July 10, 13
Creating an object:
var obj = new Object();
// Or via the object literal
var obj = {};
Wednesday, July 10, 13
Adding attributes:
var obj = {};
obj.a = 15;
obj.bark = function() {
return “Woof!”;
};
Wednesday, July 10, 13
Adding attributes:
var obj = {
a: 15,
bark: function() {
return “Woof!”;
}
};
Wednesday, July 10, 13
Constructors:
function Point(x, y) {
this.x = x;
this.y = y;
}
var point = new Point(60, 578);
Wednesday, July 10, 13
If you forget the new:
var point = Point(60, 578);
point == undefined
x and y are now variables on the
global scope
Wednesday, July 10, 13
Ensuring
that the constructor
can work with
or without
newWednesday, July 10, 13
Constructors:
function Point(x, y) {
if (!(this instanceof Point)) {
return new Point(x, y);
}
this.x = x;
this.y = y;
}
Wednesday, July 10, 13
Modularizing
code with
closures
Wednesday, July 10, 13
(function() {
/* Everything that is declared
here is local to this closure only */
})();
Wednesday, July 10, 13
You can use closures to emulate
namespaces:
var space = (function(){
var Point = function(x, y) {
if (!(this instanceof Point)) {
return new Point(x, y);
}
this.x = x;
this.y = y;
};
return {
Point: Point
};
})();
Wednesday, July 10, 13
You can use closures to emulate
namespaces:
var pt = new space.Point(60, 568);
Wednesday, July 10, 13
That’s it
at least for now...
Wednesday, July 10, 13

More Related Content

What's hot

Python queue solution with asyncio and kafka
Python queue solution with asyncio and kafkaPython queue solution with asyncio and kafka
Python queue solution with asyncio and kafkaOndřej Veselý
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲームNoritada Shimizu
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptCaridy Patino
 
The Ring programming language version 1.7 book - Part 71 of 196
The Ring programming language version 1.7 book - Part 71 of 196The Ring programming language version 1.7 book - Part 71 of 196
The Ring programming language version 1.7 book - Part 71 of 196Mahmoud Samir Fayed
 
W3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascriptW3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascriptChanghwan Yi
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montageKris Kowal
 
Zone.js 2017
Zone.js 2017Zone.js 2017
Zone.js 2017Jia Li
 
Développer avec un Simple Object Mapping Toolkit pour SQL Server
Développer avec un Simple Object Mapping Toolkit pour SQL ServerDévelopper avec un Simple Object Mapping Toolkit pour SQL Server
Développer avec un Simple Object Mapping Toolkit pour SQL ServerDenis Voituron
 
Wprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache HadoopWprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache HadoopSages
 
Ogdc 2013 lets remake the wheel
Ogdc 2013 lets remake the wheelOgdc 2013 lets remake the wheel
Ogdc 2013 lets remake the wheelSon Aris
 
OGDC2013_Lets remake the wheel_ Mr Nguyen Trung Hung
OGDC2013_Lets remake the wheel_ Mr Nguyen Trung HungOGDC2013_Lets remake the wheel_ Mr Nguyen Trung Hung
OGDC2013_Lets remake the wheel_ Mr Nguyen Trung Hungogdc
 
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyJavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyYasuharu Nakano
 
Debugging JavaScript with Chrome
Debugging JavaScript with ChromeDebugging JavaScript with Chrome
Debugging JavaScript with ChromeIgor Zalutsky
 
The Ring programming language version 1.9 book - Part 63 of 210
The Ring programming language version 1.9 book - Part 63 of 210The Ring programming language version 1.9 book - Part 63 of 210
The Ring programming language version 1.9 book - Part 63 of 210Mahmoud Samir Fayed
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017名辰 洪
 
Call stack, event loop and async programming
Call stack, event loop and async programmingCall stack, event loop and async programming
Call stack, event loop and async programmingMasters Academy
 
Fixing Web Data in Production
Fixing Web Data in ProductionFixing Web Data in Production
Fixing Web Data in ProductionAaron Knight
 
Shift Remote FRONTEND: Reactivity in Vue.JS 3 - Marko Boskovic (Barrage)
Shift Remote FRONTEND: Reactivity in Vue.JS 3 - Marko Boskovic (Barrage)Shift Remote FRONTEND: Reactivity in Vue.JS 3 - Marko Boskovic (Barrage)
Shift Remote FRONTEND: Reactivity in Vue.JS 3 - Marko Boskovic (Barrage)Shift Conference
 

What's hot (20)

Python queue solution with asyncio and kafka
Python queue solution with asyncio and kafkaPython queue solution with asyncio and kafka
Python queue solution with asyncio and kafka
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
 
The Ring programming language version 1.7 book - Part 71 of 196
The Ring programming language version 1.7 book - Part 71 of 196The Ring programming language version 1.7 book - Part 71 of 196
The Ring programming language version 1.7 book - Part 71 of 196
 
W3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascriptW3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascript
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montage
 
Zone.js 2017
Zone.js 2017Zone.js 2017
Zone.js 2017
 
Développer avec un Simple Object Mapping Toolkit pour SQL Server
Développer avec un Simple Object Mapping Toolkit pour SQL ServerDévelopper avec un Simple Object Mapping Toolkit pour SQL Server
Développer avec un Simple Object Mapping Toolkit pour SQL Server
 
Wprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache HadoopWprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache Hadoop
 
Ogdc 2013 lets remake the wheel
Ogdc 2013 lets remake the wheelOgdc 2013 lets remake the wheel
Ogdc 2013 lets remake the wheel
 
OGDC2013_Lets remake the wheel_ Mr Nguyen Trung Hung
OGDC2013_Lets remake the wheel_ Mr Nguyen Trung HungOGDC2013_Lets remake the wheel_ Mr Nguyen Trung Hung
OGDC2013_Lets remake the wheel_ Mr Nguyen Trung Hung
 
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyJavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
 
Debugging JavaScript with Chrome
Debugging JavaScript with ChromeDebugging JavaScript with Chrome
Debugging JavaScript with Chrome
 
Moar tools for asynchrony!
Moar tools for asynchrony!Moar tools for asynchrony!
Moar tools for asynchrony!
 
The Ring programming language version 1.9 book - Part 63 of 210
The Ring programming language version 1.9 book - Part 63 of 210The Ring programming language version 1.9 book - Part 63 of 210
The Ring programming language version 1.9 book - Part 63 of 210
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017
 
Call stack, event loop and async programming
Call stack, event loop and async programmingCall stack, event loop and async programming
Call stack, event loop and async programming
 
Fixing Web Data in Production
Fixing Web Data in ProductionFixing Web Data in Production
Fixing Web Data in Production
 
The State of JavaScript
The State of JavaScriptThe State of JavaScript
The State of JavaScript
 
Shift Remote FRONTEND: Reactivity in Vue.JS 3 - Marko Boskovic (Barrage)
Shift Remote FRONTEND: Reactivity in Vue.JS 3 - Marko Boskovic (Barrage)Shift Remote FRONTEND: Reactivity in Vue.JS 3 - Marko Boskovic (Barrage)
Shift Remote FRONTEND: Reactivity in Vue.JS 3 - Marko Boskovic (Barrage)
 

Viewers also liked

Viewers also liked (13)

China presentation
China presentationChina presentation
China presentation
 
Michael phelps
Michael phelpsMichael phelps
Michael phelps
 
Michael phelps (bloc)
Michael phelps (bloc)Michael phelps (bloc)
Michael phelps (bloc)
 
India uind[1]
India uind[1]India uind[1]
India uind[1]
 
خزانات مياه المصريه الفسطينيه للتوريدات
خزانات مياه المصريه الفسطينيه للتوريداتخزانات مياه المصريه الفسطينيه للتوريدات
خزانات مياه المصريه الفسطينيه للتوريدات
 
OMEGA+
OMEGA+OMEGA+
OMEGA+
 
Mul-t-Lock Matrix
Mul-t-Lock MatrixMul-t-Lock Matrix
Mul-t-Lock Matrix
 
Exploratory study of the approach to school leadership development programmes...
Exploratory study of the approach to school leadership development programmes...Exploratory study of the approach to school leadership development programmes...
Exploratory study of the approach to school leadership development programmes...
 
Power point.
Power point.Power point.
Power point.
 
Excellent school performance at age 16 and risk of adult bipolar disorder na...
Excellent school performance at age 16 and risk of adult bipolar disorder  na...Excellent school performance at age 16 and risk of adult bipolar disorder  na...
Excellent school performance at age 16 and risk of adult bipolar disorder na...
 
China quiz
China quizChina quiz
China quiz
 
Los medios de cohesión textual
Los medios de cohesión textualLos medios de cohesión textual
Los medios de cohesión textual
 
Estructura textual
Estructura textualEstructura textual
Estructura textual
 

Similar to What they don't tell you about JavaScript

ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016Manoj Kumar
 
Javascript & Ajax Basics
Javascript & Ajax BasicsJavascript & Ajax Basics
Javascript & Ajax BasicsRichard Paul
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015NAVER / MusicPlatform
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changeshayato
 
Reactive programming with RxJS - ByteConf 2018
Reactive programming with RxJS - ByteConf 2018Reactive programming with RxJS - ByteConf 2018
Reactive programming with RxJS - ByteConf 2018Tracy Lee
 
Watch out: Observables are here to stay
Watch out: Observables are here to stayWatch out: Observables are here to stay
Watch out: Observables are here to stayGuilherme Ventura
 
RxJS Evolved
RxJS EvolvedRxJS Evolved
RxJS Evolvedtrxcllnt
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oopLearningTech
 
Code level change propagation in virtual platform
Code level change propagation in virtual platformCode level change propagation in virtual platform
Code level change propagation in virtual platformHaiderAli650468
 
Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Developing High Performance Websites and Modern Apps with JavaScript and HTML5Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Developing High Performance Websites and Modern Apps with JavaScript and HTML5Doris Chen
 

Similar to What they don't tell you about JavaScript (20)

ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
 
Javascript & Ajax Basics
Javascript & Ajax BasicsJavascript & Ajax Basics
Javascript & Ajax Basics
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 
Javascript
JavascriptJavascript
Javascript
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
 
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
Myraytracer
MyraytracerMyraytracer
Myraytracer
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changes
 
Reactive programming with RxJS - ByteConf 2018
Reactive programming with RxJS - ByteConf 2018Reactive programming with RxJS - ByteConf 2018
Reactive programming with RxJS - ByteConf 2018
 
Angular2 rxjs
Angular2 rxjsAngular2 rxjs
Angular2 rxjs
 
Watch out: Observables are here to stay
Watch out: Observables are here to stayWatch out: Observables are here to stay
Watch out: Observables are here to stay
 
Groovy
GroovyGroovy
Groovy
 
RxJS Evolved
RxJS EvolvedRxJS Evolved
RxJS Evolved
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
 
Code level change propagation in virtual platform
Code level change propagation in virtual platformCode level change propagation in virtual platform
Code level change propagation in virtual platform
 
Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Developing High Performance Websites and Modern Apps with JavaScript and HTML5Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Developing High Performance Websites and Modern Apps with JavaScript and HTML5
 
8558537werr.pptx
8558537werr.pptx8558537werr.pptx
8558537werr.pptx
 

Recently uploaded

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 

Recently uploaded (20)

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 

What they don't tell you about JavaScript

  • 1. /** * southWest * Gets the southwestern quadrant of the tree * return {Quadtree} **/ Quadtree.prototype.southWest = function() { return new Quadtree( new space2d.Point( this._origin.x, Math.floor(this._size.y / 2) ), new space2d.Point( Math.floor(this._size.x / 2), this._size.y ), this ); }; /** * southEast * Gets the southeastern quadrant of the tree * return {Quadtree} **/ Quadtree.prototype.southEast = function() { return new Quadtree( new space2d.Point( Math.floor(this._size.x / 2), Math.floor(this._size.y / 2) ), new space2d.Point( this._size.x, this._size.y ), this ); }; JavaScript What they don’t tell you about Raphael Cruzeiro http://raphaelcruzeiro.com @rcdeveloper Wednesday, July 10, 13
  • 2. What does JavaScript have in common with Java? Wednesday, July 10, 13
  • 3. What does JavaScript have in common with Java? The first four letters of its name. Wednesday, July 10, 13
  • 4. It actually has a lot more in common with Python and other dynamic and functional languages Wednesday, July 10, 13
  • 6. It was created by Netscape to enhance web pages. Wednesday, July 10, 13
  • 7. It is used today not only in the browser but also to create desktop widgets and server-side code. Wednesday, July 10, 13
  • 9. “The problem with JavaScript is that nobody tries to learn it before writing applications with it.” - Douglas Crockford Wednesday, July 10, 13
  • 10. JavaScript makes it easy to write terrible code. Wednesday, July 10, 13
  • 11. var currentId; var lastViewPort; var precision = Math.pow(10, 4); var maxPointNumber = 100; var circleOverlays = []; function didViewPortChange() { var minLat = lastViewPort.getSouthWest().lat() - (lastViewPort.getNorthEast().lat() - lastViewPort.getSouthWest().lat()); var minLng = lastViewPort.getSouthWest().lng() - (lastViewPort.getNorthEast().lng() - lastViewPort.getSouthWest().lng()); var maxLat = lastViewPort.getNorthEast().lat() + (lastViewPort.getNorthEast().lat() - lastViewPort.getSouthWest().lat()); var maxLng = lastViewPort.getNorthEast().lng() + (lastViewPort.getNorthEast().lng() - lastViewPort.getSouthWest().lng()); if ($.fn.jqMap.getMap().getBounds().getNorthEast().lat() > maxLat || $.fn.jqMap.getMap().getBounds().getNorthEast().lng() > maxLng || $.fn.jqMap.getMap().getBounds().getSouthWest().lat() < minLat || $.fn.jqMap.getMap().getBounds().getSouthWest().lng() < minLng) { return true; } else { return false; } } Really bad code: Wednesday, July 10, 13
  • 12. var currentId; var lastViewPort; var precision = Math.pow(10, 4); var maxPointNumber = 100; var circleOverlays = []; function didViewPortChange() { var minLat = lastViewPort.getSouthWest().lat() - (lastViewPort.getNorthEast().lat() - lastViewPort.getSouthWest().lat()); var minLng = lastViewPort.getSouthWest().lng() - (lastViewPort.getNorthEast().lng() - lastViewPort.getSouthWest().lng()); var maxLat = lastViewPort.getNorthEast().lat() + (lastViewPort.getNorthEast().lat() - lastViewPort.getSouthWest().lat()); var maxLng = lastViewPort.getNorthEast().lng() + (lastViewPort.getNorthEast().lng() - lastViewPort.getSouthWest().lng()); if ($.fn.jqMap.getMap().getBounds().getNorthEast().lat() > maxLat || $.fn.jqMap.getMap().getBounds().getNorthEast().lng() > maxLng || $.fn.jqMap.getMap().getBounds().getSouthWest().lat() < minLat || $.fn.jqMap.getMap().getBounds().getSouthWest().lng() < minLng) { return true; } else { return false; } } Really bad code: GUILTY Wednesday, July 10, 13
  • 14. var something = 4; Wednesday, July 10, 13
  • 15. When declaring variables on the global scope you make your code more susceptible to name clashes. Wednesday, July 10, 13
  • 16. In JavaScript a function delimits the scope of variables Wednesday, July 10, 13
  • 17. var something = 4; function foo () { somethingElse = something + 4; return somethingElse; }; foo(); Accidental use of global variables Wednesday, July 10, 13
  • 19. var something = 4; var somethingElse = 7; function foo () { console.log(something); console.log(somethingElse); var something = “This is confusing.”; console.log(something); }; foo(); Wednesday, July 10, 13
  • 20. var something = 4; var somethingElse = 7; function foo () { console.log(something); console.log(somethingElse); var something = “This is confusing.”; console.log(something); }; foo(); Outputs: undefined 7 This is confusing. Wednesday, July 10, 13
  • 22. Pretty much everything is an object in JavaScript Wednesday, July 10, 13
  • 23. With a few exceptions: •Number •String •Boolean •null •undefined Wednesday, July 10, 13
  • 24. A side-note about Numbers: •There is only one type for representing all numbers. •It is represented in memory as a 64-bit floating point •IEEE-754 > 0.1 + 0.2 0.30000000000000004 Wednesday, July 10, 13
  • 25. Creating an object: var obj = new Object(); // Or via the object literal var obj = {}; Wednesday, July 10, 13
  • 26. Adding attributes: var obj = {}; obj.a = 15; obj.bark = function() { return “Woof!”; }; Wednesday, July 10, 13
  • 27. Adding attributes: var obj = { a: 15, bark: function() { return “Woof!”; } }; Wednesday, July 10, 13
  • 28. Constructors: function Point(x, y) { this.x = x; this.y = y; } var point = new Point(60, 578); Wednesday, July 10, 13
  • 29. If you forget the new: var point = Point(60, 578); point == undefined x and y are now variables on the global scope Wednesday, July 10, 13
  • 30. Ensuring that the constructor can work with or without newWednesday, July 10, 13
  • 31. Constructors: function Point(x, y) { if (!(this instanceof Point)) { return new Point(x, y); } this.x = x; this.y = y; } Wednesday, July 10, 13
  • 33. (function() { /* Everything that is declared here is local to this closure only */ })(); Wednesday, July 10, 13
  • 34. You can use closures to emulate namespaces: var space = (function(){ var Point = function(x, y) { if (!(this instanceof Point)) { return new Point(x, y); } this.x = x; this.y = y; }; return { Point: Point }; })(); Wednesday, July 10, 13
  • 35. You can use closures to emulate namespaces: var pt = new space.Point(60, 568); Wednesday, July 10, 13
  • 36. That’s it at least for now... Wednesday, July 10, 13