SlideShare uma empresa Scribd logo
1 de 37
Baixar para ler 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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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)
 

Mais de 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
 

Mais de 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
 

Último

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
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
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
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
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
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
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 

Último (20)

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
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
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
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
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
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
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 

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