SlideShare a Scribd company logo
Javascript
the
New Parts
federico.galassi@cleancode.it
slideshare.net/fgalassi
• Short history of javascript
• State of the onion
• The new parts
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
ES 3.1
small
fixes
ES 4
heavy
stuff
split
ES 3.1
Ecmascript
5th edition
the winner
the loser
ES 4
Harmony
ES5
just fixes
javascript
• Short history of javascript
• State of the onion
• The new parts
Better
object oriented
programming
Javascript
is prototypal
surname: “simpsons”
simpsons
name: “bart”
bart
prototype
bart.surname
>  “simpsons”
Wannabe classical
function  Simpsons(name)  {
this.name  =  name
}
Simpsons.prototype.surname  =  
“simpsons”
bart  =  new  Simpsons(“bart”)
constructor
class
object
Ugly
Create objects
simpsons  =  {  surname:  “simpsons”  }
bart  =  Object.create(simpsons)
bart.name  =  “bart”
bart.age  =  10
hugo  =  Object.create(bart)
hugo.name  =  “hugo”
hugo.nature  =  “evil”
object
object
object
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
bart.age
>  10
Properties
were values
Object.getOwnPropertyDescriptor(
bart,  “age”
)
>  {
value:  10,
enumerable:  true,
writable:  true,
configurable:  true
}
Properties
now configurable
Object.defineProperty(bart,  “age”,  {
value:  10,
enumerable:  true,
writable:  true,
configurable:  true
})
Properties
can be defined
Object.defineProperties(bart,  {
name:  {
value:  “bart”,
enumerable:  true,
writable:  true,
configurable:  true
},
age:  {
value:  10,
enumerable:  true,
writable:  true,
configurable:  true
}
})
More than one
bart  =  Object.create(simpsons,  {
name:  {
value:  “bart”,
enumerable:  true,
writable:  true,
configurable:  true
},
age:  {
value:  10,
enumerable:  true,
writable:  true,
configurable:  true
}
})
At creation time
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
//  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”)
No more
annoyances
JOY
• Short history of javascript
• State of the onion
• The new parts
State of the
Onion
Onion because
you can start crying
http://kangax.github.com/es5-compat-table/
7 8 9
no IE6
I don’t
shoot the
red cross
http://kangax.github.com/es5-compat-table/
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
http://kangax.github.com/es5-compat-table/
10.1 10.6 10.7
My pick is
chrome
chrome 7
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
federico.galassi@cleancode.it
Questions?

More Related Content

PDF
Threequals - Case Equality in Ruby
PDF
Go Java, Go!
PDF
The Not Java That's Not Scala
PPTX
Non-Relational Databases
PDF
My Adventures In Objective-C (A Rubyists Perspective)
PDF
ScotRuby - Dark side of ruby
PDF
Ruby - Uma Introdução
ODP
Moose - YAPC::NA 2012
Threequals - Case Equality in Ruby
Go Java, Go!
The Not Java That's Not Scala
Non-Relational Databases
My Adventures In Objective-C (A Rubyists Perspective)
ScotRuby - Dark side of ruby
Ruby - Uma Introdução
Moose - YAPC::NA 2012

Viewers also liked (20)

PDF
You too can be a bedwetting antfucker: Bruce Lawson, Opera, Fronteers 2011
PDF
HTML5 multimedia - where we are, where we're going
PPT
HTML 5 Accessibility
PDF
Leveraging HTML 5.0
PPS
PDF
WebVR with Three.js!
PPTX
Firefox Extension Development
PDF
JavaScript Web Workers
PDF
Web vr creative_vr
PDF
Quick dive into WebVR
PDF
WebVR - JAX 2016
PDF
WebRTC - On Standards, Identity and Telco Strategy
PDF
20160713 webvr
PPTX
Introduction to The VR Web
PPT
eXo SEA - JavaScript Introduction Training
PDF
WebRTC: A front-end perspective
PDF
JavaScript and Web Standards Sitting in a Tree
PPTX
Photo and photo
PPTX
Web Front End - (HTML5, CSS3, JavaScript) ++
PDF
WebRTC Reborn - Cloud Expo / WebRTC Summit
You too can be a bedwetting antfucker: Bruce Lawson, Opera, Fronteers 2011
HTML5 multimedia - where we are, where we're going
HTML 5 Accessibility
Leveraging HTML 5.0
WebVR with Three.js!
Firefox Extension Development
JavaScript Web Workers
Web vr creative_vr
Quick dive into WebVR
WebVR - JAX 2016
WebRTC - On Standards, Identity and Telco Strategy
20160713 webvr
Introduction to The VR Web
eXo SEA - JavaScript Introduction Training
WebRTC: A front-end perspective
JavaScript and Web Standards Sitting in a Tree
Photo and photo
Web Front End - (HTML5, CSS3, JavaScript) ++
WebRTC Reborn - Cloud Expo / WebRTC Summit
Ad

Similar to Javascript the New Parts (20)

PDF
Javascript the New Parts v2
PPTX
ES6: Features + Rails
ODP
AST Transformations
ODP
Naïveté vs. Experience
PPTX
ES6 is Nigh
KEY
jRuby: The best of both worlds
PDF
Es6 to es5
PDF
Everything is Permitted: Extending Built-ins
PDF
Privet Kotlin (Windy City DevFest)
PDF
JavaScript - new features in ECMAScript 6
PPTX
JS Fest 2018. Douglas Crockford. The Better Parts
PDF
Node Boot Camp
PDF
Idiomatic Javascript (ES5 to ES2015+)
PDF
Game Design and Development Workshop Day 1
ODP
Groovy Ast Transformations (greach)
KEY
Uses & Abuses of Mocks & Stubs
PDF
AkJS Meetup - ES6++
PDF
React Native Evening
PDF
Jsonsaga 100605143125-phpapp02
ODP
Dynamic Python
Javascript the New Parts v2
ES6: Features + Rails
AST Transformations
Naïveté vs. Experience
ES6 is Nigh
jRuby: The best of both worlds
Es6 to es5
Everything is Permitted: Extending Built-ins
Privet Kotlin (Windy City DevFest)
JavaScript - new features in ECMAScript 6
JS Fest 2018. Douglas Crockford. The Better Parts
Node Boot Camp
Idiomatic Javascript (ES5 to ES2015+)
Game Design and Development Workshop Day 1
Groovy Ast Transformations (greach)
Uses & Abuses of Mocks & Stubs
AkJS Meetup - ES6++
React Native Evening
Jsonsaga 100605143125-phpapp02
Dynamic Python
Ad

More from Federico Galassi (9)

PDF
Vim, the Way of the Keyboard
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
Vim, the Way of the Keyboard
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
A comparative study of natural language inference in Swahili using monolingua...
PDF
Hybrid model detection and classification of lung cancer
PPTX
1. Introduction to Computer Programming.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
DP Operators-handbook-extract for the Mautical Institute
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
OMC Textile Division Presentation 2021.pptx
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
A comparative study of natural language inference in Swahili using monolingua...
Hybrid model detection and classification of lung cancer
1. Introduction to Computer Programming.pptx
Unlocking AI with Model Context Protocol (MCP)
Building Integrated photovoltaic BIPV_UPV.pdf
cloud_computing_Infrastucture_as_cloud_p
DP Operators-handbook-extract for the Mautical Institute
SOPHOS-XG Firewall Administrator PPT.pptx
Encapsulation_ Review paper, used for researhc scholars
Assigned Numbers - 2025 - Bluetooth® Document
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Zenith AI: Advanced Artificial Intelligence
Web App vs Mobile App What Should You Build First.pdf
Encapsulation theory and applications.pdf
Hindi spoken digit analysis for native and non-native speakers
A novel scalable deep ensemble learning framework for big data classification...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
OMC Textile Division Presentation 2021.pptx
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...

Javascript the New Parts