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

PDF
JS Level Up: Prototypes
PDF
Proxies are Awesome!
PDF
ES2015 (ES6) Overview
ODP
ES6 PPT FOR 2016
KEY
PDF
Ruby 1.9
PDF
Coffeescript: No really, it's just Javascript
PDF
Introduction to CoffeeScript
JS Level Up: Prototypes
Proxies are Awesome!
ES2015 (ES6) Overview
ES6 PPT FOR 2016
Ruby 1.9
Coffeescript: No really, it's just Javascript
Introduction to CoffeeScript

What's hot (20)

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

Viewers also liked (13)

PPSX
vim - Tips and_tricks
PDF
Decorators Lightning Talk for Triangle JavaScript
PDF
Dev Tooling for your Technohipster Startup using aws, docker, tmux, vim & ope...
PDF
Introduction to vim
PDF
Vim, the Way of the Keyboard
PDF
Vim and tmux
PPTX
Vim survival guide
PPTX
Tmux and Tmuxinator ~ Rise of the Machines
PDF
Let's talk about neovim
PDF
Vim Hacks
PDF
Effective text editing with vim
PDF
Vim python-mode
PDF
Vim สั่งได้ดั่งใจ #bcbk4
vim - Tips and_tricks
Decorators Lightning Talk for Triangle JavaScript
Dev Tooling for your Technohipster Startup using aws, docker, tmux, vim & ope...
Introduction to vim
Vim, the Way of the Keyboard
Vim and tmux
Vim survival guide
Tmux and Tmuxinator ~ Rise of the Machines
Let's talk about neovim
Vim Hacks
Effective text editing with vim
Vim python-mode
Vim สั่งได้ดั่งใจ #bcbk4
Ad

Similar to Javascript the New Parts v2 (20)

PDF
Javascript the New Parts
PDF
Short intro to ECMAScript
PDF
Introduction to web programming for java and c# programmers by @drpicox
KEY
JavaScript Neednt Hurt - JavaBin talk
PDF
Whats new in ES2019
PDF
Advanced JavaScript Development
PDF
JavaScript Good Practices
PPTX
ES6: Features + Rails
PPTX
Object oriented javascript
PDF
ECMAScript 6 new features
PPTX
The JavaScript Programming Language
PDF
JavaScript for PHP developers
PDF
The Future of JavaScript (Ajax Exp '07)
PPTX
Awesomeness of JavaScript…almost
PDF
ECMAScript2015
PPTX
JavaScript (without DOM)
PPTX
All of javascript
PDF
JavaScript 1.8.5: New Features Explored
KEY
Exciting JavaScript - Part I
DOC
Jsphp 110312161301-phpapp02
Javascript the New Parts
Short intro to ECMAScript
Introduction to web programming for java and c# programmers by @drpicox
JavaScript Neednt Hurt - JavaBin talk
Whats new in ES2019
Advanced JavaScript Development
JavaScript Good Practices
ES6: Features + Rails
Object oriented javascript
ECMAScript 6 new features
The JavaScript Programming Language
JavaScript for PHP developers
The Future of JavaScript (Ajax Exp '07)
Awesomeness of JavaScript…almost
ECMAScript2015
JavaScript (without DOM)
All of javascript
JavaScript 1.8.5: New Features Explored
Exciting JavaScript - Part I
Jsphp 110312161301-phpapp02

More from Federico Galassi (8)

PDF
The Strange World of Javascript and all its little Asynchronous Beasts
PDF
CouchApps: Requiem for Accidental Complexity
PDF
Please Don't Touch the Slow Parts V3
PDF
Event Driven Javascript
PDF
Please Don't Touch the Slow Parts V2
PDF
Please Don't Touch the Slow Parts
PDF
Javascript The Good Parts v2
PDF
Javascript The Good Parts
The Strange World of Javascript and all its little Asynchronous Beasts
CouchApps: Requiem for Accidental Complexity
Please Don't Touch the Slow Parts V3
Event Driven Javascript
Please Don't Touch the Slow Parts V2
Please Don't Touch the Slow Parts
Javascript The Good Parts v2
Javascript The Good Parts

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Spectroscopy.pptx food analysis technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Understanding_Digital_Forensics_Presentation.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
The AUB Centre for AI in Media Proposal.docx
Network Security Unit 5.pdf for BCA BBA.
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Chapter 3 Spatial Domain Image Processing.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Programs and apps: productivity, graphics, security and other tools
Unlocking AI with Model Context Protocol (MCP)
Spectroscopy.pptx food analysis technology
“AI and Expert System Decision Support & Business Intelligence Systems”
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Agricultural_Statistics_at_a_Glance_2022_0.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.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