Web Directions

Conffab

  • Speakers
  • Presentations
  • Conferences
  • Organizers
  • Topics
  • Pricing & Plans
  • Browse
  • Signup
  • Sign In
  • Speakers
  • Presentations
  • Conferences
  • Organizers
  • Topics
  • Pricing & Plans
  • Browse
  • Signup
  • Sign In
Advanced Search
Searching videos

Classing up ES6

Andy Sharman at Code 2015
Sign up for Conffab Free to watch this and hundreds of other videos for free
  • Details
  • References
  • Keypoints

The what, why, when, where and how to of ES6 classes. What ES6 classes mean for JavaScript, but importantly the pros and cons of using them. And how you can use them today.

Slides

Let’s remember a little JS history:

  • Inline scripting used to be the thing (embedded in markup).
  • Then we started using the prototype.
  • Then we started using JS to fix browser shortcomings (jquery).
  • Then we started building on top of JS itself (client-side mvc, templating)

Through these latter stages the libraries were creating classes – but they weren’t true classes, so to speak.

ES6 Classes give…

  • inheritance
  • constructors
  • supers
  • getters/setters
  • default params
  • rest params (allows you to receive an unknown number of params)
  • arrow functions (=>)

Isn’t all this just syntactic sugar? Yes… to an extent… but it helps create clean, understandable code. While this is possible in prototypal JS it’s easy to go wrong, or it takes a lot of time.

Support? Evergreen browsers, IE edge, node/io… but there is a lot of red in the support chart.

You end up needing transpilers, but there are transpilers (babel, traceur) so why not?

@udjamaflip

…

Jess Telford – scope chains and closures without the hand waving

Web Directions Code 2015
(photo by Steven Cooper)

1. Scope

  • var – lexical scoping
  • let – block scoping
  • const – block scoping

1.5 Hoisting

  • JS does 2 pass parsing.
  • First pass (hoisting) gives scope – variables get ‘hoisted’ up to the top of the function.
  • This is where lots of confusing bugs begin. Google this if you aren’t comfortable with it.

1 Scopes…

  • Scopes can be nested
  • You can access outer scope but not inner scope.
  • You can have multiple inner scopes
  • This does indeed look like a tree of scopes when you look from outer to inner (top down)
  • When you look the other way, inner to outer, you get a chain (bottom up) not a tree

2 Scope chains

  • If you look for a value, JS walks up the scope chain; if nothing has that value you end up in the global scope.

3 Closures

  • Closures occur when an inner scope references a variable in outer scope.
  • This closes over the referenced variable.

4 Garbage Collection

  • GC kicks in when all the code that might need a value has been executed

5 Shadowing

  • This one is a good concept but a lot of people don’t understand it too well
  • When a value is defined more than once in a scope chain, JS reaches the first one and stops; the top-most scope is not closed over.
  • You can avoid a lot of problems here by emulating hoisting and putting all your vars at the top of scope. Use a linter to enforce this!

If you are still not sure:

  • Nodeschool.io
  • npm install -g scope-chains-closures (self paced workshop)

 

You may also be interested in

Thumbnail for Once More with Feeling

Once More with Feeling

Tim Kadlec

Thumbnail for CSS Grid Layout

CSS Grid Layout

Rachel Andrew

Thumbnail for Flexing Your Layout Muscles – A Pragmatic Look at Flexbox

Flexing Your Layout Muscles – A Pragmatic Look at Flexbox

Stephanie Rewis

Thumbnail for The Power and Responsibility of Unicode Adoption

The Power and Responsibility of Unicode Adoption

Katie McLaughlin

Thumbnail for Does Your Web App Speak Schadenfreude?

Does Your Web App Speak Schadenfreude?

Greg Rewis

Thumbnail for CSS: Code Smell Sanitation

CSS: Code Smell Sanitation

Fiona Chan

Thumbnail for Zen of JavaScript

Zen of JavaScript

Dmitry Baranovskiy

Thumbnail for Progressing Your Web Apps With Service Worker

Progressing Your Web Apps With Service Worker

Marcos Caceres

More presentations from Code 2015

    Thumbnail for The State of the Animation

    The State of the Animation

    Rachel Nabors

    Thumbnail for What Comes Next for the Web Platform?

    What Comes Next for the Web Platform?

    Alex Russell

    Thumbnail for Async and Await

    Async and Await

    James Hunter

    Thumbnail for Async Frontiers in JavaScript

    Async Frontiers in JavaScript

    Domenic Denicola

    Thumbnail for Canvas Cold War

    Canvas Cold War

    Simon Swain

    Thumbnail for Current Best Practice in Front End Ops

    Current Best Practice in Front End Ops

    Alex Sexton

    Thumbnail for Stop the Fanaticism – Using the Right Tools for the Job

    Stop the Fanaticism – Using the Right Tools for the Job

    Kassandra Perch

    Thumbnail for Pop-up Accessibility

    Pop-up Accessibility

    Rhiana Heath

Conffab
  • About
  • Speakers
  • Presentations
  • Conferences
  • Contact
  • Sign in
Sign Up

© Conffab 2025