SlideShare a Scribd company logo
Javascript
    the
 New Parts
     v2

federico.galassi@cleancode.it
slideshare.net/fgalassi
• Short history of javascript
• The new parts
• State of the onion
Javascript
 public in
   1996
No time to fix
Standard 1999
 Ecmascript
  3rd edition

      “Worst name ever”
TC39
Committee
Years later...
                  “It turns out that standard bodies are
                   not good places to innovate. That’s
                   what laboratories and startups are
                     for. Standards must be drafted by
                                consensus.”




http://yuiblog.com/blog/2008/08/14/premature-standardization/
They couldn’t agree
split

ES 3.1            ES 4
small            heavy
fixes             stuff
the winner


   ES 3.1
Ecmascript
5th edition
the loser



  ES 4
Harmony
ES5
 just fixes
javascript
• Short history of javascript
• The new parts
• State of the onion
Better
object oriented
 programming
Javascript
           is prototypal
bart                        simpsons
                prototype
name: “bart”                surname: “simpsons”




bart.surname
>  “simpsons”
Wannabe classical
function  Simpsons(name)  {
                                  constructor
  this.name  =  name
}

Simpsons.prototype.surname  =       class
“simpsons”

bart  =  new  Simpsons(“bart”)      object
Ugly
Create objects
simpsons  =  {  surname:  “simpsons”  }   object

bart  =  Object.create(simpsons)          object
bart.name  =  “bart”
bart.age  =  10

hugo  =  Object.create(bart)              object
hugo.name  =  “hugo”
hugo.nature  =  “evil”
Simple
   and
Powerful
Back to the father
homer  =  Object.create(
  Object.getPrototypeOf(bart)
)
homer.name  =  “homer”
homer.age  =  38
Getters and setters
homer  =  {
   beers:  3,
   get  drunk()  {
      return  this.beers  >  5
   }
}
homer.drunk
>  false
homer.beers  =  7
homer.drunk
>  true
Uniform
access
Properties
      were values

bart.age
>  10
Properties
   now configurable
Object.getOwnPropertyDescriptor(
   bart,  “age”
)
>  {
   value:  10,
   enumerable:  true,
   writable:  true,
   configurable:  true
}
Properties
    can be defined
Object.defineProperty(bart,  “age”,  {
   value:  10,
   enumerable:  true,
   writable:  true,
   configurable:  true
})
More than one
Object.defineProperties(bart,  {
   name:  {
      value:  “bart”,
      enumerable:  true,
      writable:  true,
      configurable:  true
   },
   age:  {
      value:  10,
      enumerable:  true,
      writable:  true,
      configurable:  true
   }
})
At creation time
bart  =  Object.create(simpsons,  {
   name:  {
       value:  “bart”,
       enumerable:  true,
       writable:  true,
       configurable:  true
   },
   age:  {
       value:  10,
       enumerable:  true,
       writable:  true,
       configurable:  true
   }
})
Better
security
writable
  Can i assign to it ?
Object.defineProperty(bart,  “age”,  {
   value:  10,
   writable:  false
})
bart.age  =  5
>  5
bart.age
>  10
configurable
    Can i delete it ?
Object.defineProperty(bart,  “age”,  {
   value:  10,
   configurable:  false
})
delete  bart.age
>  false
bart.age
>  10
configurable
 Can i configure it ?
Object.defineProperty(bart,  “age”,  {
   value:  10,
   configurable:  false
})
Object.defineProperty(bart,  “age”,  {
   configurable:  true
})
>  TypeError:  Cannot  redefine  property
enumerable
     +
  writable
   security
Even more
             security
//  Can’t  add  properties
Object.preventExtensions(obj)
//  !isExtensible  +  all  configurable  =  false
Object.seal(obj)
//  isSealed  +  all  writable  =  false
Object.freeze(obj)

Object.isExtensible(obj)
Object.isSealed(obj)
Object.isFrozen(obj)
The road to
safe mashups
Better
extensibility
enumerable
Does for/in show it up ?
Object.defineProperty(bart,  “phobia”,  {
   value:  “coffins”,
   enumerable:  false
})

//  Like  for/in  and  collect  keys
Object.keys(bart)
>  [“name”,  “surname”,  “age”]
No more
pollution
Hide behavior

Object.defineProperty(bart,  “play”,  {
   value:  function()  {  ..play..  },
   enumerable:  false
})
natives finally
        extensible !
Object.defineProperty(Array.prototype,  
“last”,  {
   value:  function()  {
      return  this[this.length  -­‐  1]
   },
   enumerable:  false
})

[4,3,5,1].last()
>  1
more native
         with getter
Object.defineProperty(Array.prototype,  
“last”,  {
   get:  function()  {
      return  this[this.length  -­‐  1]
   },
   enumerable:  false
})

[4,3,5,1].last
>  1
works with
             DOM
Object.defineProperty(HTMLElement.prototype,  
“classes”,  {
   get:  function()  {
      return  this.getAttribute(“class”)
                            .split(/s+/)
   },
   enumerable:  false
})

$(“<div  class=‘one  two’  />”).get(0).classes
>  [“one”,  “two”]
The world
 is yours
Better
      performance
//  Native  json

JSON.parse(string)
JSON.stringify(object)
Better
         functional
       programming
[1,  2,  3].map(double)
>  [2,  4,  6]
[2,  4,  6].every(isEven)
>  true
[1,  2,  3].filter(isEven)
>  [2]

//  forEach,  some,  reduce,  reduceRight
//  indexOf,  lastIndexOf
Function.bind()
var  bart  =  {
   name:  “bart”
}
var  hello  =  function(greet)  {
   return  greet  +  “i  am  “  +  this.name
}

//  bind  to  this  and  partial  application
(hello.bind(bart,  “hey”))()
>  “hey,  i  am  bart”
More operations
         on natives
Array.isArray([1,2,3])
>  true

“        hello  world          ”.trim()
>  “hello  world”

Date.now()
>  1289395540416

(new  Date).toISOString()
>  2010-­‐02-­‐20T05:52:53.649Z
No more
               annoyances
//  reserved  keyword  as  properties
bart.class  =  “cartoon”
//  abstract,  boolean,  byte,  char,  const  ...

//  OK  trailing  comma
[1,  2,  3,  ]  

//  OK  trailing  comma
{
    name:  “bart”,
}

//  8  instead  of  0  !!!
parseInt(“08”)
Strict mode
Invoking
                   //  Globally
                   “use  strict”;
                   ...  strict  code  ...


                   //  in  function  scope
                   function  test()  {
                       “use  strict”;
                       ...  strict  code  ...
                   }


http://hacks.mozilla.org/2011/01/ecmascript-5-strict-mode-in-firefox-4/
Mistakes throw errors
  “use  strict”;

  typo  =  5  //  no  var,  ERROR

  NaN  =  10  //  invalid  assign

  delete  Object.prototype  //  invalid  delete

  var  o  =  {  p:  1,  p:  2  }  //  double  property  !?

  function  dumb(p,  p)      //  double  parameter  !???

http://hacks.mozilla.org/2011/01/ecmascript-5-strict-mode-in-firefox-4/
Securing javascript
     “use  strict”;

     function  miracle()  {  return  this  }
     miracle()

     //  undefined  !!!!!




http://hacks.mozilla.org/2011/01/ecmascript-5-strict-mode-in-firefox-4/
JOY
• Short history of javascript
• The new parts
• State of the onion
State of the
   Onion
Onion because
you can start crying
7 8 9




http://kangax.github.com/es5-compat-table/
no IE6
  I don’t
shoot the
red cross
3 3.5 4




http://kangax.github.com/es5-compat-table/
3.2 4 5 webkit




http://kangax.github.com/es5-compat-table/
5 6 7 - 11




http://kangax.github.com/es5-compat-table/
10.1 10.5, 10.6, 10.7, 11, 11.10




http://kangax.github.com/es5-compat-table/
My pick is

              chrome




  firefox 4
Modern
Browsers
   OK
Old
Browsers
  ARGH
The real
problem

“IE6 is fading very slowly. Five years
 ago I predicted that IE6 would fade
          away in five years.”
even worse
Go figure
we need a Miracle
http://joind.in/3374
    federico.galassi@cleancode.it
    twitter.com/federicogalassi
    slideshare.net/fgalassi

More Related Content

What's hot

JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
Solution4Future
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
boyney123
 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScript
Todd Anglin
 
The many facets of code reuse in JavaScript
The many facets of code reuse in JavaScriptThe many facets of code reuse in JavaScript
The many facets of code reuse in JavaScript
Leonardo Borges
 
Painless Persistence with Realm
Painless Persistence with RealmPainless Persistence with Realm
Painless Persistence with Realm
Christian Melchior
 
Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6
Nilesh Jayanandana
 
Effective ES6
Effective ES6Effective ES6
Effective ES6
Teppei Sato
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
Howard Lewis Ship
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
Michael Pirnat
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Domenic Denicola
 
ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
Domenic Denicola
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
Scott Leberknight
 
Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulme...
Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulme...Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulme...
Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulme...
Data Con LA
 
Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介
Kiyotaka Oku
 
Exhibition of Atrocity
Exhibition of AtrocityExhibition of Atrocity
Exhibition of Atrocity
Michael Pirnat
 
ES6 and BEYOND
ES6 and BEYONDES6 and BEYOND
ES6 and BEYOND
Brian Patterson
 
Why (I think) CoffeeScript Is Awesome
Why (I think) CoffeeScript Is AwesomeWhy (I think) CoffeeScript Is Awesome
Why (I think) CoffeeScript Is Awesome
Jo Cranford
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
None
 
Bologna Developer Zone - About Kotlin
Bologna Developer Zone - About KotlinBologna Developer Zone - About Kotlin
Bologna Developer Zone - About Kotlin
Marco Vasapollo
 
Moose
MooseMoose

What's hot (20)

JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScript
 
The many facets of code reuse in JavaScript
The many facets of code reuse in JavaScriptThe many facets of code reuse in JavaScript
The many facets of code reuse in JavaScript
 
Painless Persistence with Realm
Painless Persistence with RealmPainless Persistence with Realm
Painless Persistence with Realm
 
Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6
 
Effective ES6
Effective ES6Effective ES6
Effective ES6
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulme...
Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulme...Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulme...
Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulme...
 
Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介
 
Exhibition of Atrocity
Exhibition of AtrocityExhibition of Atrocity
Exhibition of Atrocity
 
ES6 and BEYOND
ES6 and BEYONDES6 and BEYOND
ES6 and BEYOND
 
Why (I think) CoffeeScript Is Awesome
Why (I think) CoffeeScript Is AwesomeWhy (I think) CoffeeScript Is Awesome
Why (I think) CoffeeScript Is Awesome
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Bologna Developer Zone - About Kotlin
Bologna Developer Zone - About KotlinBologna Developer Zone - About Kotlin
Bologna Developer Zone - About Kotlin
 
Moose
MooseMoose
Moose
 

Viewers also liked

vim - Tips and_tricks
vim - Tips and_tricksvim - Tips and_tricks
vim - Tips and_tricks
Logan Palanisamy
 
Decorators Lightning Talk for Triangle JavaScript
Decorators Lightning Talk for Triangle JavaScriptDecorators Lightning Talk for Triangle JavaScript
Decorators Lightning Talk for Triangle JavaScript
Ben McCormick
 
Dev Tooling for your Technohipster Startup using aws, docker, tmux, vim & ope...
Dev Tooling for your Technohipster Startup using aws, docker, tmux, vim & ope...Dev Tooling for your Technohipster Startup using aws, docker, tmux, vim & ope...
Dev Tooling for your Technohipster Startup using aws, docker, tmux, vim & ope...
James Wickett
 
Introduction to vim
Introduction to vimIntroduction to vim
Introduction to vim
Vysakh Sreenivasan
 
Vim, the Way of the Keyboard
Vim, the Way of the KeyboardVim, the Way of the Keyboard
Vim, the Way of the Keyboard
Federico Galassi
 
Vim and tmux
Vim and tmuxVim and tmux
Vim and tmux
Zhann_
 
Vim survival guide
Vim survival guideVim survival guide
Vim survival guide
Ben McCormick
 
Tmux and Tmuxinator ~ Rise of the Machines
Tmux and Tmuxinator  ~ Rise of the MachinesTmux and Tmuxinator  ~ Rise of the Machines
Tmux and Tmuxinator ~ Rise of the Machines
Brian Loomis
 
Let's talk about neovim
Let's talk about neovimLet's talk about neovim
Let's talk about neovim
Shougo
 
Vim Hacks
Vim HacksVim Hacks
Vim Hacks
Lin Yo-An
 
Effective text editing with vim
Effective text editing with vimEffective text editing with vim
Effective text editing with vim
xprayc
 
Vim python-mode
Vim python-modeVim python-mode
Vim python-mode
Carlos Gustavo Ruiz
 
Vim สั่งได้ดั่งใจ #bcbk4
Vim สั่งได้ดั่งใจ #bcbk4Vim สั่งได้ดั่งใจ #bcbk4
Vim สั่งได้ดั่งใจ #bcbk4
Thai Pangsakulyanont
 

Viewers also liked (13)

vim - Tips and_tricks
vim - Tips and_tricksvim - Tips and_tricks
vim - Tips and_tricks
 
Decorators Lightning Talk for Triangle JavaScript
Decorators Lightning Talk for Triangle JavaScriptDecorators Lightning Talk for Triangle JavaScript
Decorators Lightning Talk for Triangle JavaScript
 
Dev Tooling for your Technohipster Startup using aws, docker, tmux, vim & ope...
Dev Tooling for your Technohipster Startup using aws, docker, tmux, vim & ope...Dev Tooling for your Technohipster Startup using aws, docker, tmux, vim & ope...
Dev Tooling for your Technohipster Startup using aws, docker, tmux, vim & ope...
 
Introduction to vim
Introduction to vimIntroduction to vim
Introduction to vim
 
Vim, the Way of the Keyboard
Vim, the Way of the KeyboardVim, the Way of the Keyboard
Vim, the Way of the Keyboard
 
Vim and tmux
Vim and tmuxVim and tmux
Vim and tmux
 
Vim survival guide
Vim survival guideVim survival guide
Vim survival guide
 
Tmux and Tmuxinator ~ Rise of the Machines
Tmux and Tmuxinator  ~ Rise of the MachinesTmux and Tmuxinator  ~ Rise of the Machines
Tmux and Tmuxinator ~ Rise of the Machines
 
Let's talk about neovim
Let's talk about neovimLet's talk about neovim
Let's talk about neovim
 
Vim Hacks
Vim HacksVim Hacks
Vim Hacks
 
Effective text editing with vim
Effective text editing with vimEffective text editing with vim
Effective text editing with vim
 
Vim python-mode
Vim python-modeVim python-mode
Vim python-mode
 
Vim สั่งได้ดั่งใจ #bcbk4
Vim สั่งได้ดั่งใจ #bcbk4Vim สั่งได้ดั่งใจ #bcbk4
Vim สั่งได้ดั่งใจ #bcbk4
 

Similar to Javascript the New Parts v2

Javascript the New Parts
Javascript the New PartsJavascript the New Parts
Javascript the New Parts
Federico Galassi
 
ES6: Features + Rails
ES6: Features + RailsES6: Features + Rails
ES6: Features + Rails
Santosh Wadghule
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
Tarek Yehia
 
ES6 is Nigh
ES6 is NighES6 is Nigh
ES6 is Nigh
Domenic Denicola
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
Troy Miles
 
ts+js
ts+jsts+js
js+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdfjs+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdf
NuttavutThongjor1
 
fullstack typescript with react and express.pdf
fullstack typescript with react and express.pdffullstack typescript with react and express.pdf
fullstack typescript with react and express.pdf
NuttavutThongjor1
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
Troy Miles
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Tsuyoshi Yamamoto
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
Dmitry Soshnikov
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
Cody Engel
 
Wakanday JS201 Best Practices
Wakanday JS201 Best PracticesWakanday JS201 Best Practices
Wakanday JS201 Best Practices
Juergen Fesslmeier
 
JavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talkJavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talk
Thomas Kjeldahl Nilsson
 
Corinna-2023.pptx
Corinna-2023.pptxCorinna-2023.pptx
Corinna-2023.pptx
Curtis Poe
 
Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)
David Atchley
 
Intro to Sail.js
Intro to Sail.jsIntro to Sail.js
Intro to Sail.js
Nicholas McClay
 
JSConf: All You Can Leet
JSConf: All You Can LeetJSConf: All You Can Leet
JSConf: All You Can Leet
johndaviddalton
 
jRuby: The best of both worlds
jRuby: The best of both worldsjRuby: The best of both worlds
jRuby: The best of both worlds
Christopher Spring
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
Troy Miles
 

Similar to Javascript the New Parts v2 (20)

Javascript the New Parts
Javascript the New PartsJavascript the New Parts
Javascript the New Parts
 
ES6: Features + Rails
ES6: Features + RailsES6: Features + Rails
ES6: Features + Rails
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
 
ES6 is Nigh
ES6 is NighES6 is Nigh
ES6 is Nigh
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
 
ts+js
ts+jsts+js
ts+js
 
js+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdfjs+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdf
 
fullstack typescript with react and express.pdf
fullstack typescript with react and express.pdffullstack typescript with react and express.pdf
fullstack typescript with react and express.pdf
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
 
Wakanday JS201 Best Practices
Wakanday JS201 Best PracticesWakanday JS201 Best Practices
Wakanday JS201 Best Practices
 
JavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talkJavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talk
 
Corinna-2023.pptx
Corinna-2023.pptxCorinna-2023.pptx
Corinna-2023.pptx
 
Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)
 
Intro to Sail.js
Intro to Sail.jsIntro to Sail.js
Intro to Sail.js
 
JSConf: All You Can Leet
JSConf: All You Can LeetJSConf: All You Can Leet
JSConf: All You Can Leet
 
jRuby: The best of both worlds
jRuby: The best of both worldsjRuby: The best of both worlds
jRuby: The best of both worlds
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 

More from Federico Galassi

The Strange World of Javascript and all its little Asynchronous Beasts
The Strange World of Javascript and all its little Asynchronous BeastsThe Strange World of Javascript and all its little Asynchronous Beasts
The Strange World of Javascript and all its little Asynchronous Beasts
Federico Galassi
 
CouchApps: Requiem for Accidental Complexity
CouchApps: Requiem for Accidental ComplexityCouchApps: Requiem for Accidental Complexity
CouchApps: Requiem for Accidental Complexity
Federico Galassi
 
Please Don't Touch the Slow Parts V3
Please Don't Touch the Slow Parts V3Please Don't Touch the Slow Parts V3
Please Don't Touch the Slow Parts V3
Federico Galassi
 
Event Driven Javascript
Event Driven JavascriptEvent Driven Javascript
Event Driven Javascript
Federico Galassi
 
Please Don't Touch the Slow Parts V2
Please Don't Touch the Slow Parts V2Please Don't Touch the Slow Parts V2
Please Don't Touch the Slow Parts V2
Federico Galassi
 
Please Don't Touch the Slow Parts
Please Don't Touch the Slow PartsPlease Don't Touch the Slow Parts
Please Don't Touch the Slow Parts
Federico Galassi
 
Javascript The Good Parts v2
Javascript The Good Parts v2Javascript The Good Parts v2
Javascript The Good Parts v2
Federico Galassi
 
Javascript The Good Parts
Javascript The Good PartsJavascript The Good Parts
Javascript The Good Parts
Federico Galassi
 

More from Federico Galassi (8)

The Strange World of Javascript and all its little Asynchronous Beasts
The Strange World of Javascript and all its little Asynchronous BeastsThe Strange World of Javascript and all its little Asynchronous Beasts
The Strange World of Javascript and all its little Asynchronous Beasts
 
CouchApps: Requiem for Accidental Complexity
CouchApps: Requiem for Accidental ComplexityCouchApps: Requiem for Accidental Complexity
CouchApps: Requiem for Accidental Complexity
 
Please Don't Touch the Slow Parts V3
Please Don't Touch the Slow Parts V3Please Don't Touch the Slow Parts V3
Please Don't Touch the Slow Parts V3
 
Event Driven Javascript
Event Driven JavascriptEvent Driven Javascript
Event Driven Javascript
 
Please Don't Touch the Slow Parts V2
Please Don't Touch the Slow Parts V2Please Don't Touch the Slow Parts V2
Please Don't Touch the Slow Parts V2
 
Please Don't Touch the Slow Parts
Please Don't Touch the Slow PartsPlease Don't Touch the Slow Parts
Please Don't Touch the Slow Parts
 
Javascript The Good Parts v2
Javascript The Good Parts v2Javascript The Good Parts v2
Javascript The Good Parts v2
 
Javascript The Good Parts
Javascript The Good PartsJavascript The Good Parts
Javascript The Good Parts
 

Recently uploaded

Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
TIPNGVN2
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Zilliz
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 

Recently uploaded (20)

Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 

Javascript the New Parts v2

  • 1. Javascript the New Parts v2 federico.galassi@cleancode.it slideshare.net/fgalassi
  • 2. • Short history of javascript • The new parts • State of the onion
  • 5. Standard 1999 Ecmascript 3rd edition “Worst name ever”
  • 7. Years later... “It turns out that standard bodies are not good places to innovate. That’s what laboratories and startups are for. Standards must be drafted by consensus.” http://yuiblog.com/blog/2008/08/14/premature-standardization/
  • 9. split ES 3.1 ES 4 small heavy fixes stuff
  • 10. the winner ES 3.1 Ecmascript 5th edition
  • 11. the loser ES 4 Harmony
  • 13. • Short history of javascript • The new parts • State of the onion
  • 15. Javascript is prototypal bart simpsons prototype name: “bart” surname: “simpsons” bart.surname >  “simpsons”
  • 16. Wannabe classical function  Simpsons(name)  { constructor this.name  =  name } Simpsons.prototype.surname  =   class “simpsons” bart  =  new  Simpsons(“bart”) object
  • 17. Ugly
  • 18. Create objects simpsons  =  {  surname:  “simpsons”  } object bart  =  Object.create(simpsons) object bart.name  =  “bart” bart.age  =  10 hugo  =  Object.create(bart) object hugo.name  =  “hugo” hugo.nature  =  “evil”
  • 19. Simple and Powerful
  • 20. Back to the father homer  =  Object.create( Object.getPrototypeOf(bart) ) homer.name  =  “homer” homer.age  =  38
  • 21. Getters and setters homer  =  { beers:  3, get  drunk()  { return  this.beers  >  5 } } homer.drunk >  false homer.beers  =  7 homer.drunk >  true
  • 23. Properties were values bart.age >  10
  • 24. Properties now configurable Object.getOwnPropertyDescriptor( bart,  “age” ) >  { value:  10, enumerable:  true, writable:  true, configurable:  true }
  • 25. Properties can be defined Object.defineProperty(bart,  “age”,  { value:  10, enumerable:  true, writable:  true, configurable:  true })
  • 26. More than one Object.defineProperties(bart,  { name:  { value:  “bart”, enumerable:  true, writable:  true, configurable:  true }, age:  { value:  10, enumerable:  true, writable:  true, configurable:  true } })
  • 27. At creation time bart  =  Object.create(simpsons,  { name:  { value:  “bart”, enumerable:  true, writable:  true, configurable:  true }, age:  { value:  10, enumerable:  true, writable:  true, configurable:  true } })
  • 29. writable Can i assign to it ? Object.defineProperty(bart,  “age”,  { value:  10, writable:  false }) bart.age  =  5 >  5 bart.age >  10
  • 30. configurable Can i delete it ? Object.defineProperty(bart,  “age”,  { value:  10, configurable:  false }) delete  bart.age >  false bart.age >  10
  • 31. configurable Can i configure it ? Object.defineProperty(bart,  “age”,  { value:  10, configurable:  false }) Object.defineProperty(bart,  “age”,  { configurable:  true }) >  TypeError:  Cannot  redefine  property
  • 32. enumerable + writable security
  • 33. Even more security //  Can’t  add  properties Object.preventExtensions(obj) //  !isExtensible  +  all  configurable  =  false Object.seal(obj) //  isSealed  +  all  writable  =  false Object.freeze(obj) Object.isExtensible(obj) Object.isSealed(obj) Object.isFrozen(obj)
  • 34. The road to safe mashups
  • 36. enumerable Does for/in show it up ? Object.defineProperty(bart,  “phobia”,  { value:  “coffins”, enumerable:  false }) //  Like  for/in  and  collect  keys Object.keys(bart) >  [“name”,  “surname”,  “age”]
  • 38. Hide behavior Object.defineProperty(bart,  “play”,  { value:  function()  {  ..play..  }, enumerable:  false })
  • 39. natives finally extensible ! Object.defineProperty(Array.prototype,   “last”,  { value:  function()  { return  this[this.length  -­‐  1] }, enumerable:  false }) [4,3,5,1].last() >  1
  • 40. more native with getter Object.defineProperty(Array.prototype,   “last”,  { get:  function()  { return  this[this.length  -­‐  1] }, enumerable:  false }) [4,3,5,1].last >  1
  • 41. works with DOM Object.defineProperty(HTMLElement.prototype,   “classes”,  { get:  function()  { return  this.getAttribute(“class”)                      .split(/s+/) }, enumerable:  false }) $(“<div  class=‘one  two’  />”).get(0).classes >  [“one”,  “two”]
  • 42. The world is yours
  • 43. Better performance //  Native  json JSON.parse(string) JSON.stringify(object)
  • 44. Better functional programming [1,  2,  3].map(double) >  [2,  4,  6] [2,  4,  6].every(isEven) >  true [1,  2,  3].filter(isEven) >  [2] //  forEach,  some,  reduce,  reduceRight //  indexOf,  lastIndexOf
  • 45. Function.bind() var  bart  =  { name:  “bart” } var  hello  =  function(greet)  { return  greet  +  “i  am  “  +  this.name } //  bind  to  this  and  partial  application (hello.bind(bart,  “hey”))() >  “hey,  i  am  bart”
  • 46. More operations on natives Array.isArray([1,2,3]) >  true “        hello  world          ”.trim() >  “hello  world” Date.now() >  1289395540416 (new  Date).toISOString() >  2010-­‐02-­‐20T05:52:53.649Z
  • 47. No more annoyances //  reserved  keyword  as  properties bart.class  =  “cartoon” //  abstract,  boolean,  byte,  char,  const  ... //  OK  trailing  comma [1,  2,  3,  ]   //  OK  trailing  comma { name:  “bart”, } //  8  instead  of  0  !!! parseInt(“08”)
  • 49. Invoking //  Globally “use  strict”; ...  strict  code  ... //  in  function  scope function  test()  {    “use  strict”;    ...  strict  code  ... } http://hacks.mozilla.org/2011/01/ecmascript-5-strict-mode-in-firefox-4/
  • 50. Mistakes throw errors “use  strict”; typo  =  5  //  no  var,  ERROR NaN  =  10  //  invalid  assign delete  Object.prototype  //  invalid  delete var  o  =  {  p:  1,  p:  2  }  //  double  property  !? function  dumb(p,  p)      //  double  parameter  !??? http://hacks.mozilla.org/2011/01/ecmascript-5-strict-mode-in-firefox-4/
  • 51. Securing javascript “use  strict”; function  miracle()  {  return  this  } miracle() //  undefined  !!!!! http://hacks.mozilla.org/2011/01/ecmascript-5-strict-mode-in-firefox-4/
  • 52. JOY
  • 53. • Short history of javascript • The new parts • State of the onion
  • 54. State of the Onion
  • 55. Onion because you can start crying
  • 57. no IE6 I don’t shoot the red cross
  • 59. 3.2 4 5 webkit http://kangax.github.com/es5-compat-table/
  • 60. 5 6 7 - 11 http://kangax.github.com/es5-compat-table/
  • 61. 10.1 10.5, 10.6, 10.7, 11, 11.10 http://kangax.github.com/es5-compat-table/
  • 62. My pick is chrome firefox 4
  • 65. The real problem “IE6 is fading very slowly. Five years ago I predicted that IE6 would fade away in five years.”
  • 68. we need a Miracle
  • 69. http://joind.in/3374 federico.galassi@cleancode.it twitter.com/federicogalassi slideshare.net/fgalassi