Updated version of talk "Javascript the New Parts".
I gave this at JsDay on May 12th 2011.
I updated with latest stats and improved es5 coverage, most notably strict mode.
Abstract:
At last, ecmascript 5th edition is landing in all modern browsers. What are the new parts of the language and how can they help us to write better code?
Also
http://federico.galassi.net/
http://www.jsday.it/
Follow me on Twitter!
https://twitter.com/federicogalassi
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/
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”]
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”)