JSFoo 2017

JSFoo is a conference about JavaScript and everything related.

Lakshman Prasad

@becomingguru

Loop like an ES6 Native

Submitted Feb 9, 2017

One of the first things someone learns in programming is to loop, i.e. perform a sequence of steps on a set of elements. Any developer - beginner to advanced, writes atleast a few loops every hour. It’s ubiqutious nature merits a deep dive into the fundamentals of looping.

Let’s explore the various ways to loop in Javascript and it’s appropriate use cases. We explore loops in the imperative style and functional variants such as map and reduce. We look into the implementations of underscore.js, lodash and other such libraries that were often used with ES5.

ES6 comes bundled with many of these including the new generator syntax, which we will dig deep into, so your loops going forward can be both machine-efficient, and developer-friendly.

Outline

  • Basics
    • Various ways to loop
    • for ... of loop and it’s comparison
    • for ... of loop working on Maps, Sets, Args, DOM collections
    • Examples from other languages
    • “Array Like” and “Duck Typing”
    • Benefits with example - Unit Testing
  • Within the builtins
    • Iterators returned
    • Iterables consumed
      • spread operator
      • min, max etc.
    • Consistent interface
  • Under the hood - The Protocols
    • Iterator Protocol
    • Iterable Protocol
    • Examples
    • Custom Iterators/iterables
  • Generators
    • Builtin function
    • Lazy evaluation
    • Implements both iterator and iterable protocol
    • Keywords - yield, yield*, function*
  • Generators example
    • Example of a normal program
    • Comparison
    • Example of AJAX chaining
  • Generators Algorithm example
    • Recursive algorithm for fibonacci
    • Generator algo
    • Recursion algorithm for factors of a number
    • Generator algorithm
  • Your own generators in the real world
    • Examples

Speaker bio

Lakshman Prasad has been programming for a decade and finds ways to do efficiently, things that are often done. He works for a management consulting firm in developing technology solutions.

Comments

{{ gettext('Login to leave a comment') }}

{{ gettext('Post a comment…') }}
{{ gettext('New comment') }}
{{ formTitle }}

{{ errorMsg }}

{{ gettext('No comments posted yet') }}

Hosted by

JSFoo is a forum for discussing UI engineering; fullstack development; web applications engineering, performance, security and design; accessibility; and latest developments in #JavaScript. Follow JSFoo on Twitter more