SlideShare a Scribd company logo
1 of 37
Download to read offline
JavaScript
                            Do you speak it!


Tuesday, August 2, 2011
!"#$%&'(&'&)*
                   *
                   +,&-*.%/012%*3%*4&5#663*
                   78(9::;#%7/<=$&>:"#$%&'(&'&)*




Tuesday, August 2, 2011
“The world’s most

                                  misunderstood

                          programming language”




Tuesday, August 2, 2011
We’ll talk about

                          why JavaScript is the most misunderstood
                          programming language

                          Object Oriented Programming in JavaScript

                          function scope, closures, circular references

                          making the web a little faster



Tuesday, August 2, 2011
JavaScript

                          aka Mocha

                                        aka LiveScript

                          aka JScript
                                              aka ECMAScript




Tuesday, August 2, 2011
Java... Script?


                          somehow related to Java?

                          maybe a subset?

                          less capable interpreted version of Java?




Tuesday, August 2, 2011
Java... Script?


                          developed by Netscape in 1997 (vs. 3.0 in 1999)

                          Java prefix intended to create confusion

                          JavaScript is not interpreted Java




Tuesday, August 2, 2011
Design errors
                                                           1 + “1” = ?
                                                           1 + +”1” = ?
                          overloading “+” means both addition and
                          string concatenation with type conversion

                          error-prone “with” statement

                          reserved word policies are much too strict

                          semicolon insertion was “a huge mistake”



Tuesday, August 2, 2011
Bad implementations


                          earlier implementations were buggy

                          embedded horribly in browsers

                          did not respect the ECMA standard




Tuesday, August 2, 2011
Evolution

                          first versions of JavaScript were quite weak

                          no exception handling, inner functions

                          in its present form, it’s a full OOP language

                          ECMAScript 5.1




Tuesday, August 2, 2011
Overview

                          types and operators, core objects, methods

                          does not have classes, but this functionality is
                          accomplished with object prototypes

                          functions are objects (and can be passed
                          around as parameters)




Tuesday, August 2, 2011
(Loosely) Types
                                                          typeof
                          Number                          instanceof

                          String

                          Boolean

                          Object (Function, Array, Date, RegExp)

                          Null

                          Undefined


Tuesday, August 2, 2011
Lisp in C’s clothing


                          C-like syntax (curly braces, for statement...)

                          appears to be a procedural language

                          it’s actually a functional language!




Tuesday, August 2, 2011
Haskell vs. JS
          palindr :: [Int] -> Bool
          palindr [] = True
          palindr [x] = True
          palindr xs = (head xs == last xs)
            && palindr (tail (init xs))

          function palindr(xs) {
            var i, len = xs.length;
            for (i = 0; i < len / 2; i++)
              if (xs[i] !== xs[len - i - 1])
                return false;

                return true;
          }

Tuesday, August 2, 2011
Objects
                          JavaScript is fundamentally about objects

                          usually implemented as hashtables

                          objects are created using constructors

                          use a namespace for them (don’t modify
                          objects you don’t own)

                          use JS sugar: var obj = {}; and var arr = [];


Tuesday, August 2, 2011
OOP
                                             class Dog {
                                               public string name = “”;
                                               public int yearsOld = 0;
                          polymorphism           void bark(int times);
                                                 void bark(float volume);
                          encapsulation          void sleep();
                                             }
                          inheritance
                                             class Pudel : Dog {
                                               public int cuteness = 5;
                          abstractization    }

                                             Dog pinky = new Dog();
                                             Dog leyla = new Pudel();

Tuesday, August 2, 2011
Objects in JavaScript
          MyNamespace.Dog = function(){
             this.name = “”;
             this.yearsOld = 0;
          };

          MyNamespace.Dog.prototype = {
             bark: function(param){
             },
             sleep: function(){
             }
          };

          var pinky = new Dog();
          var leyla = new Dog();
          leyla.cuteness = 5;

Tuesday, August 2, 2011
Objects in JavaScript
          MyNamespace.Dog = function(){
             this.name = “”;
             this.yearsOld = 0;
          };                              no private members?

          MyNamespace.Dog.prototype = {
             bark: function(param){
             },
             sleep: function(){
             }
          };

          var pinky = new Dog();
          var leyla = new Dog();
          leyla.cuteness = 5;

Tuesday, August 2, 2011
Closures
          function foo(a, b){
            function bar() {
              return a + b;
            }

                return bar();
                                    var res1 = foo(5, 2);
          }
                                    var res2 = foo2(5, 2);
          function foo2(a, b){
                                    var res3 = res2(3);
            function bar(c) {
              return a + b + c;
            }

                return bar;
          }

Tuesday, August 2, 2011
Private members
          MyNamespace.Dog = function(){
            var name = “”;
            var yearsOld = 0;

                this.bark = function(param){
                   if (“Number” === typeof param) {
                   }
                   else {
                   }
                };
                this.sleep = function(){
                };
          };

          var pinky = new Dog();

Tuesday, August 2, 2011
Private members
          MyNamespace.Dog = function(paramName, paramYearsOld){
            var name = paramName;
            var yearsOld = paramYearsOld;

                this.bark = function(param){
                };
                this.sleep = function(){
                };

                get nrYearsOld(){
                   return yearsOld;
                };
          };

          var pinky = new Dog();
          console.log(pinky.nrYearsOld);
Tuesday, August 2, 2011
Why is JavaScript
                                slow?


                           Bad compilation?



Tuesday, August 2, 2011
Why is JavaScript
                                slow?


                           No compilation!*



Tuesday, August 2, 2011
Why is JavaScript
                                slow?


                           No compilation!*

             *yes, interpreters are a lot smarter these days, but..

Tuesday, August 2, 2011
Scope chains
          function scope1(){
            var elem2;

                function scope2(){
                  var elem2;

                      function scope3(){
                        var elem3;
                        var func = window.alert;

                          return {
                            something: elem4,
                            somethingElse: elem5
                          }
                      }
                }
          }
Tuesday, August 2, 2011
Memory leaks
          function leakMemory(){
            var elem = somethingThatOccupiesLotsOfMemory;

                function inner(){
                };

                return inner;
          }

          var res1 = leakMemory();
          var res2 = leakMemory();



Tuesday, August 2, 2011
Circular references
          function leakMemory(){
            var elem = document.getElementById(“someId”);

                elem.onclick = function(){
                };
          }




Tuesday, August 2, 2011
Circular references
          function dontLeakMemory(){
            var elem = document.getElementById(“someId”);

                elem.onclick = function(){
                };

                elem = null;
          }




Tuesday, August 2, 2011
Circular references
          function leakMemory(){
            var elem = document.getElementById(“someId”);

                elem.onclick = function(){
                };

                return elem;
          }




Tuesday, August 2, 2011
Circular references
          function dontLeakMemory(){
            var elem = document.getElementById(“someId”);

                elem.onclick = function(){
                };

                try {
                  return elem;
                }
                finally {
                  elem = null;
                }
          }

Tuesday, August 2, 2011
Scope binding
          function scopeBinding(){
            this.elem = {}

                function addMemberToElem(){
                   this.elem.newProperty = 5; // fail
                };

                addMemberToElem();
          }




Tuesday, August 2, 2011
Scope binding
          function scopeBinding(){
            this.elem = {};

                function addMemberToElem(){
                   this.elem.newProperty = 5;
                };

                addMemberToElem.call(this);
          }




Tuesday, August 2, 2011
Scope binding
          function scopeBinding(){
            this.elem = {}

                function addMemberToElem(propertyValue){
                   this.elem.newProperty = propertyValue;
                };

                addMemberToElem.call(this, 5);
          }




Tuesday, August 2, 2011
Scope binding
          function scopeBinding(){
            this.elem = {}

                var addMemberToElem = function(propertyValue){
                  this.elem.newProperty = propertyValue;
                }.bind(this);

                addMemberToElem(5);
          }




Tuesday, August 2, 2011
“But why should I do OOP
                             with JavaScript?”

Tuesday, August 2, 2011
“But why should I do OOP
                             with JavaScript?”

Tuesday, August 2, 2011
?
Tuesday, August 2, 2011

More Related Content

What's hot

JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101Sven Lito
 
NLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by OrdinaNLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by OrdinaMartijn Blankestijn
 
Javascript basic course
Javascript basic courseJavascript basic course
Javascript basic courseTran Khoa
 
7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in KotlinLuca Guadagnini
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScriptFu Cheng
 
모던자바의 역습
모던자바의 역습모던자바의 역습
모던자바의 역습DoHyun Jung
 
Google Guava & EMF @ GTUG Nantes
Google Guava & EMF @ GTUG NantesGoogle Guava & EMF @ GTUG Nantes
Google Guava & EMF @ GTUG Nantesmikaelbarbero
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScriptNascenia IT
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingRichardWarburton
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsMark Baker
 
Basic Javascript
Basic JavascriptBasic Javascript
Basic JavascriptBunlong Van
 
Why we cannot ignore Functional Programming
Why we cannot ignore Functional ProgrammingWhy we cannot ignore Functional Programming
Why we cannot ignore Functional ProgrammingMario Fusco
 
Functional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting LambdasFunctional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting LambdasGanesh Samarthyam
 
Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1José Paumard
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentationVan Huong
 

What's hot (20)

Workshop Scala
Workshop ScalaWorkshop Scala
Workshop Scala
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101
 
NLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by OrdinaNLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by Ordina
 
Javascript basic course
Javascript basic courseJavascript basic course
Javascript basic course
 
7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin
 
Java tutorial
Java tutorialJava tutorial
Java tutorial
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
모던자바의 역습
모던자바의 역습모던자바의 역습
모던자바의 역습
 
scala
scalascala
scala
 
Google Guava & EMF @ GTUG Nantes
Google Guava & EMF @ GTUG NantesGoogle Guava & EMF @ GTUG Nantes
Google Guava & EMF @ GTUG Nantes
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional Programming
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL Iterators
 
Basic Javascript
Basic JavascriptBasic Javascript
Basic Javascript
 
Why we cannot ignore Functional Programming
Why we cannot ignore Functional ProgrammingWhy we cannot ignore Functional Programming
Why we cannot ignore Functional Programming
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Functional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting LambdasFunctional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting Lambdas
 
Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
 

Viewers also liked

De la validarea formularelor Web la porcii verzi (utilizarea automatelor in c...
De la validarea formularelor Web la porcii verzi (utilizarea automatelor in c...De la validarea formularelor Web la porcii verzi (utilizarea automatelor in c...
De la validarea formularelor Web la porcii verzi (utilizarea automatelor in c...Sabin Buraga
 
Pagini web mai rapide
Pagini web mai rapidePagini web mai rapide
Pagini web mai rapideAlex Burciu
 
Alec Williams - Author Allies, Poet Partners and Story Stars: Working with Cr...
Alec Williams - Author Allies, Poet Partners and Story Stars: Working with Cr...Alec Williams - Author Allies, Poet Partners and Story Stars: Working with Cr...
Alec Williams - Author Allies, Poet Partners and Story Stars: Working with Cr...SLA
 
JPSSE - Partido State University
JPSSE - Partido State UniversityJPSSE - Partido State University
JPSSE - Partido State UniversityWilly Prilles
 

Viewers also liked (6)

De la validarea formularelor Web la porcii verzi (utilizarea automatelor in c...
De la validarea formularelor Web la porcii verzi (utilizarea automatelor in c...De la validarea formularelor Web la porcii verzi (utilizarea automatelor in c...
De la validarea formularelor Web la porcii verzi (utilizarea automatelor in c...
 
[TW] Node.js
[TW] Node.js[TW] Node.js
[TW] Node.js
 
Pagini web mai rapide
Pagini web mai rapidePagini web mai rapide
Pagini web mai rapide
 
Frontline 2.3
Frontline 2.3Frontline 2.3
Frontline 2.3
 
Alec Williams - Author Allies, Poet Partners and Story Stars: Working with Cr...
Alec Williams - Author Allies, Poet Partners and Story Stars: Working with Cr...Alec Williams - Author Allies, Poet Partners and Story Stars: Working with Cr...
Alec Williams - Author Allies, Poet Partners and Story Stars: Working with Cr...
 
JPSSE - Partido State University
JPSSE - Partido State UniversityJPSSE - Partido State University
JPSSE - Partido State University
 

Similar to Javascript, Do you speak it!

Master in javascript
Master in javascriptMaster in javascript
Master in javascriptRobbin Zhao
 
Javascript Basics - part 1
Javascript Basics - part 1Javascript Basics - part 1
Javascript Basics - part 1Kasia Drzyzga
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdfHiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdfHiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdfHiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdfHiroshi Ono
 
An Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsAn Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsMiles Sabin
 
2014 holden - databricks umd scala crash course
2014   holden - databricks umd scala crash course2014   holden - databricks umd scala crash course
2014 holden - databricks umd scala crash courseHolden Karau
 
jQuery with javascript training by Technnovation Labs
jQuery with javascript training by Technnovation LabsjQuery with javascript training by Technnovation Labs
jQuery with javascript training by Technnovation LabsPrasad Shende
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPsmueller_sandsmedia
 
Javascript Objects Deep Dive
Javascript Objects Deep DiveJavascript Objects Deep Dive
Javascript Objects Deep DiveManish Jangir
 
JavaScript Beyond jQuery
JavaScript Beyond jQueryJavaScript Beyond jQuery
JavaScript Beyond jQueryBobby Bryant
 
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)OpenBlend society
 

Similar to Javascript, Do you speak it! (20)

Dynamic Python
Dynamic PythonDynamic Python
Dynamic Python
 
Master in javascript
Master in javascriptMaster in javascript
Master in javascript
 
Javascript Basics - part 1
Javascript Basics - part 1Javascript Basics - part 1
Javascript Basics - part 1
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
An Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsAn Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional Paradigms
 
Programming with Freedom & Joy
Programming with Freedom & JoyProgramming with Freedom & Joy
Programming with Freedom & Joy
 
2014 holden - databricks umd scala crash course
2014   holden - databricks umd scala crash course2014   holden - databricks umd scala crash course
2014 holden - databricks umd scala crash course
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
oojs
oojsoojs
oojs
 
jQuery with javascript training by Technnovation Labs
jQuery with javascript training by Technnovation LabsjQuery with javascript training by Technnovation Labs
jQuery with javascript training by Technnovation Labs
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHP
 
JavsScript OOP
JavsScript OOPJavsScript OOP
JavsScript OOP
 
Java
JavaJava
Java
 
Javascript Objects Deep Dive
Javascript Objects Deep DiveJavascript Objects Deep Dive
Javascript Objects Deep Dive
 
JavaScript Beyond jQuery
JavaScript Beyond jQueryJavaScript Beyond jQuery
JavaScript Beyond jQuery
 
JavaSE 7
JavaSE 7JavaSE 7
JavaSE 7
 
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
 

More from Victor Porof

Firefox WebGL developer tools
Firefox WebGL developer toolsFirefox WebGL developer tools
Firefox WebGL developer toolsVictor Porof
 
Firefox developer tools
Firefox developer toolsFirefox developer tools
Firefox developer toolsVictor Porof
 
Processing.js vs. three.js
Processing.js vs. three.jsProcessing.js vs. three.js
Processing.js vs. three.jsVictor Porof
 
Cityquest - Developing games for the mobile devices
Cityquest - Developing games for the mobile devicesCityquest - Developing games for the mobile devices
Cityquest - Developing games for the mobile devicesVictor Porof
 
Web3D - Semantic standards, WebGL, HCI
Web3D - Semantic standards, WebGL, HCIWeb3D - Semantic standards, WebGL, HCI
Web3D - Semantic standards, WebGL, HCIVictor Porof
 
Chameleon game engine
Chameleon game engineChameleon game engine
Chameleon game engineVictor Porof
 
Developing web apps using Java and the Play framework
Developing web apps using Java and the Play frameworkDeveloping web apps using Java and the Play framework
Developing web apps using Java and the Play frameworkVictor Porof
 
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on RailsBeginners' guide to Ruby on Rails
Beginners' guide to Ruby on RailsVictor Porof
 
Introduction to the XNA framework
Introduction to the XNA frameworkIntroduction to the XNA framework
Introduction to the XNA frameworkVictor Porof
 
Introduction to 3D and shaders
Introduction to 3D and shadersIntroduction to 3D and shaders
Introduction to 3D and shadersVictor Porof
 

More from Victor Porof (11)

Firefox WebGL developer tools
Firefox WebGL developer toolsFirefox WebGL developer tools
Firefox WebGL developer tools
 
Firefox developer tools
Firefox developer toolsFirefox developer tools
Firefox developer tools
 
Js in the open
Js in the openJs in the open
Js in the open
 
Processing.js vs. three.js
Processing.js vs. three.jsProcessing.js vs. three.js
Processing.js vs. three.js
 
Cityquest - Developing games for the mobile devices
Cityquest - Developing games for the mobile devicesCityquest - Developing games for the mobile devices
Cityquest - Developing games for the mobile devices
 
Web3D - Semantic standards, WebGL, HCI
Web3D - Semantic standards, WebGL, HCIWeb3D - Semantic standards, WebGL, HCI
Web3D - Semantic standards, WebGL, HCI
 
Chameleon game engine
Chameleon game engineChameleon game engine
Chameleon game engine
 
Developing web apps using Java and the Play framework
Developing web apps using Java and the Play frameworkDeveloping web apps using Java and the Play framework
Developing web apps using Java and the Play framework
 
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on RailsBeginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
 
Introduction to the XNA framework
Introduction to the XNA frameworkIntroduction to the XNA framework
Introduction to the XNA framework
 
Introduction to 3D and shaders
Introduction to 3D and shadersIntroduction to 3D and shaders
Introduction to 3D and shaders
 

Recently uploaded

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 

Recently uploaded (20)

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 

Javascript, Do you speak it!

  • 1. JavaScript Do you speak it! Tuesday, August 2, 2011
  • 2. !"#$%&'(&'&)* * +,&-*.%/012%*3%*4&5#663* 78(9::;#%7/<=$&>:"#$%&'(&'&)* Tuesday, August 2, 2011
  • 3. “The world’s most misunderstood programming language” Tuesday, August 2, 2011
  • 4. We’ll talk about why JavaScript is the most misunderstood programming language Object Oriented Programming in JavaScript function scope, closures, circular references making the web a little faster Tuesday, August 2, 2011
  • 5. JavaScript aka Mocha aka LiveScript aka JScript aka ECMAScript Tuesday, August 2, 2011
  • 6. Java... Script? somehow related to Java? maybe a subset? less capable interpreted version of Java? Tuesday, August 2, 2011
  • 7. Java... Script? developed by Netscape in 1997 (vs. 3.0 in 1999) Java prefix intended to create confusion JavaScript is not interpreted Java Tuesday, August 2, 2011
  • 8. Design errors 1 + “1” = ? 1 + +”1” = ? overloading “+” means both addition and string concatenation with type conversion error-prone “with” statement reserved word policies are much too strict semicolon insertion was “a huge mistake” Tuesday, August 2, 2011
  • 9. Bad implementations earlier implementations were buggy embedded horribly in browsers did not respect the ECMA standard Tuesday, August 2, 2011
  • 10. Evolution first versions of JavaScript were quite weak no exception handling, inner functions in its present form, it’s a full OOP language ECMAScript 5.1 Tuesday, August 2, 2011
  • 11. Overview types and operators, core objects, methods does not have classes, but this functionality is accomplished with object prototypes functions are objects (and can be passed around as parameters) Tuesday, August 2, 2011
  • 12. (Loosely) Types typeof Number instanceof String Boolean Object (Function, Array, Date, RegExp) Null Undefined Tuesday, August 2, 2011
  • 13. Lisp in C’s clothing C-like syntax (curly braces, for statement...) appears to be a procedural language it’s actually a functional language! Tuesday, August 2, 2011
  • 14. Haskell vs. JS palindr :: [Int] -> Bool palindr [] = True palindr [x] = True palindr xs = (head xs == last xs) && palindr (tail (init xs)) function palindr(xs) { var i, len = xs.length; for (i = 0; i < len / 2; i++) if (xs[i] !== xs[len - i - 1]) return false; return true; } Tuesday, August 2, 2011
  • 15. Objects JavaScript is fundamentally about objects usually implemented as hashtables objects are created using constructors use a namespace for them (don’t modify objects you don’t own) use JS sugar: var obj = {}; and var arr = []; Tuesday, August 2, 2011
  • 16. OOP class Dog { public string name = “”; public int yearsOld = 0; polymorphism void bark(int times); void bark(float volume); encapsulation void sleep(); } inheritance class Pudel : Dog { public int cuteness = 5; abstractization } Dog pinky = new Dog(); Dog leyla = new Pudel(); Tuesday, August 2, 2011
  • 17. Objects in JavaScript MyNamespace.Dog = function(){ this.name = “”; this.yearsOld = 0; }; MyNamespace.Dog.prototype = { bark: function(param){ }, sleep: function(){ } }; var pinky = new Dog(); var leyla = new Dog(); leyla.cuteness = 5; Tuesday, August 2, 2011
  • 18. Objects in JavaScript MyNamespace.Dog = function(){ this.name = “”; this.yearsOld = 0; }; no private members? MyNamespace.Dog.prototype = { bark: function(param){ }, sleep: function(){ } }; var pinky = new Dog(); var leyla = new Dog(); leyla.cuteness = 5; Tuesday, August 2, 2011
  • 19. Closures function foo(a, b){ function bar() { return a + b; } return bar(); var res1 = foo(5, 2); } var res2 = foo2(5, 2); function foo2(a, b){ var res3 = res2(3); function bar(c) { return a + b + c; } return bar; } Tuesday, August 2, 2011
  • 20. Private members MyNamespace.Dog = function(){ var name = “”; var yearsOld = 0; this.bark = function(param){ if (“Number” === typeof param) { } else { } }; this.sleep = function(){ }; }; var pinky = new Dog(); Tuesday, August 2, 2011
  • 21. Private members MyNamespace.Dog = function(paramName, paramYearsOld){ var name = paramName; var yearsOld = paramYearsOld; this.bark = function(param){ }; this.sleep = function(){ }; get nrYearsOld(){ return yearsOld; }; }; var pinky = new Dog(); console.log(pinky.nrYearsOld); Tuesday, August 2, 2011
  • 22. Why is JavaScript slow? Bad compilation? Tuesday, August 2, 2011
  • 23. Why is JavaScript slow? No compilation!* Tuesday, August 2, 2011
  • 24. Why is JavaScript slow? No compilation!* *yes, interpreters are a lot smarter these days, but.. Tuesday, August 2, 2011
  • 25. Scope chains function scope1(){ var elem2; function scope2(){ var elem2; function scope3(){ var elem3; var func = window.alert; return { something: elem4, somethingElse: elem5 } } } } Tuesday, August 2, 2011
  • 26. Memory leaks function leakMemory(){ var elem = somethingThatOccupiesLotsOfMemory; function inner(){ }; return inner; } var res1 = leakMemory(); var res2 = leakMemory(); Tuesday, August 2, 2011
  • 27. Circular references function leakMemory(){ var elem = document.getElementById(“someId”); elem.onclick = function(){ }; } Tuesday, August 2, 2011
  • 28. Circular references function dontLeakMemory(){ var elem = document.getElementById(“someId”); elem.onclick = function(){ }; elem = null; } Tuesday, August 2, 2011
  • 29. Circular references function leakMemory(){ var elem = document.getElementById(“someId”); elem.onclick = function(){ }; return elem; } Tuesday, August 2, 2011
  • 30. Circular references function dontLeakMemory(){ var elem = document.getElementById(“someId”); elem.onclick = function(){ }; try { return elem; } finally { elem = null; } } Tuesday, August 2, 2011
  • 31. Scope binding function scopeBinding(){ this.elem = {} function addMemberToElem(){ this.elem.newProperty = 5; // fail }; addMemberToElem(); } Tuesday, August 2, 2011
  • 32. Scope binding function scopeBinding(){ this.elem = {}; function addMemberToElem(){ this.elem.newProperty = 5; }; addMemberToElem.call(this); } Tuesday, August 2, 2011
  • 33. Scope binding function scopeBinding(){ this.elem = {} function addMemberToElem(propertyValue){ this.elem.newProperty = propertyValue; }; addMemberToElem.call(this, 5); } Tuesday, August 2, 2011
  • 34. Scope binding function scopeBinding(){ this.elem = {} var addMemberToElem = function(propertyValue){ this.elem.newProperty = propertyValue; }.bind(this); addMemberToElem(5); } Tuesday, August 2, 2011
  • 35. “But why should I do OOP with JavaScript?” Tuesday, August 2, 2011
  • 36. “But why should I do OOP with JavaScript?” Tuesday, August 2, 2011