let
's get it started!Marek Stępień
This talk does not represent the views of my employer.
JSON.parse(str)
, JSON.stringify(obj)
Object.create()
, defineProperty()
, seal()
, freeze()
etc.Function.prototype.bind()
- bound functionsreduce
, map
, filter
etc.)All of this stuff is pretty bleeding-edge, not yet accepted by ECMA/TC-39. Everything can change and look totally different in the final ES6 spec. :-)
let
const answerToEverything = 42;
[a, b] = [5, 10];
[1,2,3].map((x) -> x*x)
Proxy
objects facilitating metaprogrammingyield x
WeakMap
function f(someArg = 5) {}
let
(JS1.7, Fx2)const answerToEverything = 42;
(JS 1.5, even in NS 6)[a, b] = [5, 10];
(JS 1.8, Fx3)[1,2,3].map(function(x) x*x)
(JS 1.8, Fx3)Proxy
objects (JS2, Fx4)yield x
(JS 1.7, Fx2)WeakMap
(Fx6)~ = differences with the final spec highly probable
Some ES6 features have a syntax that is incompatible with older JS versions, so ES6 code has to be marked in a special way. To get all the features in current Firefoxes:
<script type="application/javascript;version=1.8"> let x = 5; </script>
The final standard will surely differ here ("application/ecmascript;version=6"?)
ES6 stuff not needing new syntax can work without this type
attribute.
What will c0nsole.write
show? why?
Know the answer? NOT SO FAST! Let others think about this for a while, too! :)
var someVar
- defines a variable visible in the current function
var
appeared in the function ("hoisting")
Code from the previous example is interpreted the same way as this:
window
in browsers)
var
= accessing a global
var
throw
TEH EVILZ! Don't use it. EVER!
let
the sunshine in :)let
let
definition
let
statement
let
expression
let
definitionvar
:let varName;
let varName = expression;
let v1 = exp1, v2 = exp2, …, vN = expN
let
statementlet (variable_definitions) { code_block }
let
expressionlet (variable_definitions) expression
let
expressionlet
?const
- constant definitionsES6 says const introduces the constant in a block scope. Currently in Firefox it introduces the constant in function scope (like var) Bug 611388
Questions?
Slides powered by: CSSS by Lea Verou + marcoos' CSSS-Plugins (MIT License)
Background: untitled by John Wilson (Flickr: johnwilson1969; CC-BY-SA)
Hoisting example blatantly stolen from adequatelygood.com.
Evil crazy throw
trick originally discovered by danbeam.org.