SlideShare a Scribd company logo
1 of 24
Download to read offline
Andrew & Aaron present:




          The Future
         of JavaScript
JavaScript 1.6


    Based on ECMA-262, edition 3
●




    Implemented in Firefox 1.5
●




    Added
●




        ECMAScript for XML (aka E4X; ECMA-357)
    –

        Array extras
    –

        Array and String generics
    –
Array extras


    Location methods:
●



        indexOf()
    –

        lastIndexOf()
    –


    Iterative methods:
●



        every()
    –

        filter()
    –

        forEach()
    –

        map()
    –

        some()
    –
Iteration examples


 var ids = [ 1, 2, 3 ];
 var els = ids.map( function( i ){
      return document.getElementById( 'item_' + i ); } );
 for( var i = 0; i < els.length; i++ ){
   els[i].style.border = '1px solid';
 }

 and
 var lis = document.getElementsByTagName( 'li' );
 var evenLis = Array.filter( lis,
               function( li, i ){ return i % 2 == 1; } );
 for( var i = 0; i < evenLis.length; i++ ){
   evenLis[i].style.background = '#ccc';
 }
JavaScript 1.7


    Based on ECMA-262, edition 3
●




    Includes JS1.6 enhancements
●




    Introduced
●




        Generators & Iterators
    –

        Array comprehensions
    –

        Block scope variables
    –

        Destructuring assignment
    –
Using JS 1.7


    Implemented in Firefox 2 only
●




    Enable via MIME type:
●




    <script type="application/javascript;version=1.7">
      // code goes here
    </script>

    or
    <script type="application/javascript;version=1.7" »
            src="/path/to/my.js"></script>
Traditional iterative generation


 for( var i = 1; i < 4; i++ ){
   var ul = document.createElement( 'ul' );
   for( var j = 1; j <= i; j++ ){
     var li = document.createElement( 'li' );
     li.appendChild( document.createTextNode( j ) );
     ul.appendChild( li );
   }
   document.getElementsByTagName( 'body' »
                                  )[0].appendChild( ul );
 }
Which gives us


    1
●




    1
●




    2
●




    1
●




    2
●




    3
●
Optimized iterative generation


 var $ul = document.createElement( 'ul' );
 var $li = document.createElement( 'li' );
 for( var i = 1; i < 4; i++ ){
   var ul = $ul.cloneNode( true );
   for( var j = 1; j <= i; j++ ){
     var li = $li.cloneNode( true );
     li.appendChild( document.createTextNode( j ) );
     ul.appendChild( li );
   }
   document.getElementsByTagName( 'body' »
                                   )[0].appendChild( ul );
 }
Generator-Iterators


 function $el( tag ){
   var el = document.createElement( tag );
   while( true ){
     yield el.cloneNode( true );
   }
 }
 var $ul = $el( 'ul' ), $li = $el( 'li' );
 for( var i = 1; i < 4; i++ ){
   var ul = $ul.next();
   for( var j = 1; j <= i; j++ ){
     var li = $li.next();
     li.appendChild( document.createTextNode( j ) );
     ul.appendChild( li );
   }
   document.getElementsByTagName( 'body' »
                                  )[0].appendChild( ul );
 }
Straight Iteration


 var me = { name: 'Aaron Gustafson', age: 29,
             'eye color': 'blue', height: '5ft 11in' };
 var it = Iterator( me );
 var ul = $ul.next(), li;
 try{
   while( true ){
      li = $li.next();
      li.appendChild( document.createTextNode( »
                                            it.next() ) );
      ul.appendChild( li );
   }
 }catch( err if err instanceof StopIteration ){
   document.getElementsByTagName( 'body' »
                                   )[0].appendChild( ul );
 }catch( err ){
   alert( 'error: '+err.description );
 }
Which gives us


    name,Aaron Gustafson
●




    age,29
●




    eye color,blue
●




    height,5ft 11in
●
Alternation


 var li = document.getElementsByTagName( 'li' );
 for( var i = 0; i < li.length; i++ ){
   if( i % 2 == 0 ){
     li[i].className = 'even';
   }
 }
Generators and array creation


 function range( start, end ){
   for( var i = start; i < end; i++ ){
     yield i;
   }
 }

 var li = document.getElementsByTagName( 'li' );

 var evens = [i for ( i in range( 0, li.length ) ) »
                if ( i % 2 ==0 ) ];

 for( num in evens ) li[evens[num]].className = 'even';
let is the new black


     Only way we currently get block scope:
●




    function foo(){
      var x = 5;
      ( function(){
          var x = 10;
          alert( x );   //-> 10
        } )();
      alert( x );       //-> 5
    }
let blocks


function foo(){
  var x = 5;
  let( x = 10 ){
    alert( x );        //-> 10
  }
  alert( x );          //-> 5
}

    or if you wanna get really crazy
●



function foo(){
  var x = 5;
  let( x = x + 5 ){
    alert( x );        //-> 10
  }
  alert( x );          //-> 5
}
let expressions


function foo() {
  var x = 5;
  alert( let( x = 10 ) x ); //-> 10
  alert( x );               //-> 5
}
let in loops


for( let i = 0; i < array.length; i++ )
  doSomethingWith( array[i] );

alert( i ); //-> undefined

or
for( let i   = 0, subArray; i<array.length; i++ ){
  subArray   = array[i];
  for( let   i = 0; i < subArray.length; i++ )
    alert(   subArray[i] );
}
Like a key party in your code


    Destructuring assignment:
●




    var a = 1;
    var b = 2;
    [a, b]= [b, a];

    or
    var [c, d] = [a, b];
Return with greater flexibility


    We’ve always been able to return arrays
●




    var result = returnsArray();
    var a = result[0];
    var b = result[1];


    But now
●




    var [a,b] = returnsArray();

    or even
    var [,b] = returnsArray();
That’s not all, let’s play with JSON


 var me = { name:          'Aaron Gustafson',
            age:           29,
            'eye color':   'blue',
            height:        '5ft 11in' };

 var ul = $ul.next();

 for( let [ key, value ] in me ){
   let li = $li.next();
   li.appendChild( document.createTextNode( 'Key: ' +
                     key + ', Value: ' + value ) );
   ul.appendChild( li );
 }

 document.getElementsByTagName( 'body' »
                                )[0].appendChild( ul );
Resulting in


    Key: name, Value: Aaron Gustafson
●




    Key: age, Value: 29
●




    Key: eye color, Value: blue
●




    Key: height, Value: 5ft 11in
●
Or iterate safely over an Object


 Object.prototype.HAHAHA = "I AM THE HASH DESTRUCTOR";

 for( let [ key, value ] in me )
   alert( key ); /* 'name', 'age', 'eye color',
                    'height', 'HAHAHA' */

 function SafeHashIterator( hash, keysOnly ){
   for( let [key, value] in hash ){
     if( !hash.hasOwnProperty( key ) ) continue;
     yield keysOnly ? key : [key, value];
   }
   throw StopIteration;
 }

 for( let [key, value] in SafeHashIterator( me ) )
   alert( key ); // 'name', 'age', 'eye color', 'height'
So why should I care?

More Related Content

What's hot

Snake report ROHIT MALAV
Snake report ROHIT MALAVSnake report ROHIT MALAV
Snake report ROHIT MALAVRohit malav
 
MongoDB全機能解説2
MongoDB全機能解説2MongoDB全機能解説2
MongoDB全機能解説2Takahiro Inoue
 
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)Nikita Popov
 
MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤Takahiro Inoue
 
Template Haskell とか
Template Haskell とかTemplate Haskell とか
Template Haskell とかHiromi Ishii
 
여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala LanguageAshal aka JOKER
 
Webmontag Berlin "coffee script"
Webmontag Berlin "coffee script"Webmontag Berlin "coffee script"
Webmontag Berlin "coffee script"Webmontag Berlin
 
PHP 7 – What changed internally?
PHP 7 – What changed internally?PHP 7 – What changed internally?
PHP 7 – What changed internally?Nikita Popov
 
New text document
New text documentNew text document
New text documentPavel111212
 
Error Management: Future vs ZIO
Error Management: Future vs ZIOError Management: Future vs ZIO
Error Management: Future vs ZIOJohn De Goes
 
ios,objective tutorial
ios,objective tutorial ios,objective tutorial
ios,objective tutorial Bhavik Patel
 
LINQ Internals - STLDODN
LINQ Internals - STLDODNLINQ Internals - STLDODN
LINQ Internals - STLDODNKeith Dahlby
 

What's hot (18)

Snake report ROHIT MALAV
Snake report ROHIT MALAVSnake report ROHIT MALAV
Snake report ROHIT MALAV
 
MongoDB全機能解説2
MongoDB全機能解説2MongoDB全機能解説2
MongoDB全機能解説2
 
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)
 
MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
MongoDB Oplog入門
MongoDB Oplog入門MongoDB Oplog入門
MongoDB Oplog入門
 
Rust ⇋ JavaScript
Rust ⇋ JavaScriptRust ⇋ JavaScript
Rust ⇋ JavaScript
 
Template Haskell とか
Template Haskell とかTemplate Haskell とか
Template Haskell とか
 
여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language
 
Webmontag Berlin "coffee script"
Webmontag Berlin "coffee script"Webmontag Berlin "coffee script"
Webmontag Berlin "coffee script"
 
Functional programming with php7
Functional programming with php7Functional programming with php7
Functional programming with php7
 
Unfiltered Unveiled
Unfiltered UnveiledUnfiltered Unveiled
Unfiltered Unveiled
 
Living with garbage
Living with garbageLiving with garbage
Living with garbage
 
PHP 7 – What changed internally?
PHP 7 – What changed internally?PHP 7 – What changed internally?
PHP 7 – What changed internally?
 
New text document
New text documentNew text document
New text document
 
Error Management: Future vs ZIO
Error Management: Future vs ZIOError Management: Future vs ZIO
Error Management: Future vs ZIO
 
ios,objective tutorial
ios,objective tutorial ios,objective tutorial
ios,objective tutorial
 
LINQ Internals - STLDODN
LINQ Internals - STLDODNLINQ Internals - STLDODN
LINQ Internals - STLDODN
 

Viewers also liked

The Present and Future of JavaScript: ES2015 and Beyond
The Present and Future of JavaScript: ES2015 and BeyondThe Present and Future of JavaScript: ES2015 and Beyond
The Present and Future of JavaScript: ES2015 and BeyondNizar Khalife
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascriptShah Jalal
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScriptMichael Girouard
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptRohan Chandane
 
TechCBT: JavaScript Arrays in Depth
TechCBT: JavaScript Arrays in DepthTechCBT: JavaScript Arrays in Depth
TechCBT: JavaScript Arrays in DepthTech CBT
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScriptDonald Sipe
 
Advanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScriptAdvanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScriptecker
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptStoyan Stefanov
 
JavaScript: Past, Present, Future
JavaScript: Past, Present, FutureJavaScript: Past, Present, Future
JavaScript: Past, Present, FutureJungryul Choi
 

Viewers also liked (10)

The Present and Future of JavaScript: ES2015 and Beyond
The Present and Future of JavaScript: ES2015 and BeyondThe Present and Future of JavaScript: ES2015 and Beyond
The Present and Future of JavaScript: ES2015 and Beyond
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascript
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScript
 
TechCBT: JavaScript Arrays in Depth
TechCBT: JavaScript Arrays in DepthTechCBT: JavaScript Arrays in Depth
TechCBT: JavaScript Arrays in Depth
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Object Oriented Javascript
Object Oriented JavascriptObject Oriented Javascript
Object Oriented Javascript
 
Advanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScriptAdvanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScript
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScript
 
JavaScript: Past, Present, Future
JavaScript: Past, Present, FutureJavaScript: Past, Present, Future
JavaScript: Past, Present, Future
 

Similar to The Future of JavaScript (SXSW '07)

Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Seri Moth
 
Adding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer ToolboxAdding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer ToolboxJeff Strauss
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan Stefanov
 
ECMAScript 6 new features
ECMAScript 6 new featuresECMAScript 6 new features
ECMAScript 6 new featuresGephenSG
 
Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Lukas Ruebbelke
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairMark
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrowPete McFarlane
 
Async & Parallel in JavaScript
Async & Parallel in JavaScriptAsync & Parallel in JavaScript
Async & Parallel in JavaScriptEyal Vardi
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScriptniklal
 

Similar to The Future of JavaScript (SXSW '07) (20)

ES2015 New Features
ES2015 New FeaturesES2015 New Features
ES2015 New Features
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
Adding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer ToolboxAdding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer Toolbox
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
ES6(ES2015) is beautiful
ES6(ES2015) is beautifulES6(ES2015) is beautiful
ES6(ES2015) is beautiful
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
Javascript
JavascriptJavascript
Javascript
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
 
ECMAScript 6 new features
ECMAScript 6 new featuresECMAScript 6 new features
ECMAScript 6 new features
 
JavaScript @ CTK
JavaScript @ CTKJavaScript @ CTK
JavaScript @ CTK
 
Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015
 
Einführung in TypeScript
Einführung in TypeScriptEinführung in TypeScript
Einführung in TypeScript
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love Affair
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
Say It With Javascript
Say It With JavascriptSay It With Javascript
Say It With Javascript
 
Async & Parallel in JavaScript
Async & Parallel in JavaScriptAsync & Parallel in JavaScript
Async & Parallel in JavaScript
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
 

More from Aaron Gustafson

Delivering Critical Information and Services [JavaScript & Friends 2021]
Delivering Critical Information and Services [JavaScript & Friends 2021]Delivering Critical Information and Services [JavaScript & Friends 2021]
Delivering Critical Information and Services [JavaScript & Friends 2021]Aaron Gustafson
 
Adapting to Reality [Guest Lecture, March 2021]
Adapting to Reality [Guest Lecture, March 2021]Adapting to Reality [Guest Lecture, March 2021]
Adapting to Reality [Guest Lecture, March 2021]Aaron Gustafson
 
Designing the Conversation [Beyond Tellerrand 2019]
Designing the Conversation [Beyond Tellerrand 2019]Designing the Conversation [Beyond Tellerrand 2019]
Designing the Conversation [Beyond Tellerrand 2019]Aaron Gustafson
 
Getting Started with Progressive Web Apps [Beyond Tellerrand 2019]
Getting Started with Progressive Web Apps [Beyond Tellerrand 2019]Getting Started with Progressive Web Apps [Beyond Tellerrand 2019]
Getting Started with Progressive Web Apps [Beyond Tellerrand 2019]Aaron Gustafson
 
Progressive Web Apps: Where Do I Begin?
Progressive Web Apps: Where Do I Begin?Progressive Web Apps: Where Do I Begin?
Progressive Web Apps: Where Do I Begin?Aaron Gustafson
 
Media in the Age of PWAs [ImageCon 2019]
Media in the Age of PWAs [ImageCon 2019]Media in the Age of PWAs [ImageCon 2019]
Media in the Age of PWAs [ImageCon 2019]Aaron Gustafson
 
Adapting to Reality [Starbucks Lunch & Learn]
Adapting to Reality [Starbucks Lunch & Learn]Adapting to Reality [Starbucks Lunch & Learn]
Adapting to Reality [Starbucks Lunch & Learn]Aaron Gustafson
 
Conversational Semantics for the Web [CascadiaJS 2018]
Conversational Semantics for the Web [CascadiaJS 2018]Conversational Semantics for the Web [CascadiaJS 2018]
Conversational Semantics for the Web [CascadiaJS 2018]Aaron Gustafson
 
Better Performance === Greater Accessibility [Inclusive Design 24 2018]
Better Performance === Greater Accessibility [Inclusive Design 24 2018]Better Performance === Greater Accessibility [Inclusive Design 24 2018]
Better Performance === Greater Accessibility [Inclusive Design 24 2018]Aaron Gustafson
 
PWA: Where Do I Begin? [Microsoft Ignite 2018]
PWA: Where Do I Begin? [Microsoft Ignite 2018]PWA: Where Do I Begin? [Microsoft Ignite 2018]
PWA: Where Do I Begin? [Microsoft Ignite 2018]Aaron Gustafson
 
Designing the Conversation [Concatenate 2018]
Designing the Conversation [Concatenate 2018]Designing the Conversation [Concatenate 2018]
Designing the Conversation [Concatenate 2018]Aaron Gustafson
 
Designing the Conversation [Accessibility DC 2018]
Designing the Conversation [Accessibility DC 2018]Designing the Conversation [Accessibility DC 2018]
Designing the Conversation [Accessibility DC 2018]Aaron Gustafson
 
Performance as User Experience [AEADC 2018]
Performance as User Experience [AEADC 2018]Performance as User Experience [AEADC 2018]
Performance as User Experience [AEADC 2018]Aaron Gustafson
 
The Web Should Just Work for Everyone
The Web Should Just Work for EveryoneThe Web Should Just Work for Everyone
The Web Should Just Work for EveryoneAaron Gustafson
 
Performance as User Experience [AEA SEA 2018]
Performance as User Experience [AEA SEA 2018]Performance as User Experience [AEA SEA 2018]
Performance as User Experience [AEA SEA 2018]Aaron Gustafson
 
Performance as User Experience [An Event Apart Denver 2017]
Performance as User Experience [An Event Apart Denver 2017]Performance as User Experience [An Event Apart Denver 2017]
Performance as User Experience [An Event Apart Denver 2017]Aaron Gustafson
 
Advanced Design Methods 1, Day 2
Advanced Design Methods 1, Day 2Advanced Design Methods 1, Day 2
Advanced Design Methods 1, Day 2Aaron Gustafson
 
Advanced Design Methods 1, Day 1
Advanced Design Methods 1, Day 1Advanced Design Methods 1, Day 1
Advanced Design Methods 1, Day 1Aaron Gustafson
 
Designing the Conversation [Paris Web 2017]
Designing the Conversation [Paris Web 2017]Designing the Conversation [Paris Web 2017]
Designing the Conversation [Paris Web 2017]Aaron Gustafson
 
Exploring Adaptive Interfaces [Generate 2017]
Exploring Adaptive Interfaces [Generate 2017]Exploring Adaptive Interfaces [Generate 2017]
Exploring Adaptive Interfaces [Generate 2017]Aaron Gustafson
 

More from Aaron Gustafson (20)

Delivering Critical Information and Services [JavaScript & Friends 2021]
Delivering Critical Information and Services [JavaScript & Friends 2021]Delivering Critical Information and Services [JavaScript & Friends 2021]
Delivering Critical Information and Services [JavaScript & Friends 2021]
 
Adapting to Reality [Guest Lecture, March 2021]
Adapting to Reality [Guest Lecture, March 2021]Adapting to Reality [Guest Lecture, March 2021]
Adapting to Reality [Guest Lecture, March 2021]
 
Designing the Conversation [Beyond Tellerrand 2019]
Designing the Conversation [Beyond Tellerrand 2019]Designing the Conversation [Beyond Tellerrand 2019]
Designing the Conversation [Beyond Tellerrand 2019]
 
Getting Started with Progressive Web Apps [Beyond Tellerrand 2019]
Getting Started with Progressive Web Apps [Beyond Tellerrand 2019]Getting Started with Progressive Web Apps [Beyond Tellerrand 2019]
Getting Started with Progressive Web Apps [Beyond Tellerrand 2019]
 
Progressive Web Apps: Where Do I Begin?
Progressive Web Apps: Where Do I Begin?Progressive Web Apps: Where Do I Begin?
Progressive Web Apps: Where Do I Begin?
 
Media in the Age of PWAs [ImageCon 2019]
Media in the Age of PWAs [ImageCon 2019]Media in the Age of PWAs [ImageCon 2019]
Media in the Age of PWAs [ImageCon 2019]
 
Adapting to Reality [Starbucks Lunch & Learn]
Adapting to Reality [Starbucks Lunch & Learn]Adapting to Reality [Starbucks Lunch & Learn]
Adapting to Reality [Starbucks Lunch & Learn]
 
Conversational Semantics for the Web [CascadiaJS 2018]
Conversational Semantics for the Web [CascadiaJS 2018]Conversational Semantics for the Web [CascadiaJS 2018]
Conversational Semantics for the Web [CascadiaJS 2018]
 
Better Performance === Greater Accessibility [Inclusive Design 24 2018]
Better Performance === Greater Accessibility [Inclusive Design 24 2018]Better Performance === Greater Accessibility [Inclusive Design 24 2018]
Better Performance === Greater Accessibility [Inclusive Design 24 2018]
 
PWA: Where Do I Begin? [Microsoft Ignite 2018]
PWA: Where Do I Begin? [Microsoft Ignite 2018]PWA: Where Do I Begin? [Microsoft Ignite 2018]
PWA: Where Do I Begin? [Microsoft Ignite 2018]
 
Designing the Conversation [Concatenate 2018]
Designing the Conversation [Concatenate 2018]Designing the Conversation [Concatenate 2018]
Designing the Conversation [Concatenate 2018]
 
Designing the Conversation [Accessibility DC 2018]
Designing the Conversation [Accessibility DC 2018]Designing the Conversation [Accessibility DC 2018]
Designing the Conversation [Accessibility DC 2018]
 
Performance as User Experience [AEADC 2018]
Performance as User Experience [AEADC 2018]Performance as User Experience [AEADC 2018]
Performance as User Experience [AEADC 2018]
 
The Web Should Just Work for Everyone
The Web Should Just Work for EveryoneThe Web Should Just Work for Everyone
The Web Should Just Work for Everyone
 
Performance as User Experience [AEA SEA 2018]
Performance as User Experience [AEA SEA 2018]Performance as User Experience [AEA SEA 2018]
Performance as User Experience [AEA SEA 2018]
 
Performance as User Experience [An Event Apart Denver 2017]
Performance as User Experience [An Event Apart Denver 2017]Performance as User Experience [An Event Apart Denver 2017]
Performance as User Experience [An Event Apart Denver 2017]
 
Advanced Design Methods 1, Day 2
Advanced Design Methods 1, Day 2Advanced Design Methods 1, Day 2
Advanced Design Methods 1, Day 2
 
Advanced Design Methods 1, Day 1
Advanced Design Methods 1, Day 1Advanced Design Methods 1, Day 1
Advanced Design Methods 1, Day 1
 
Designing the Conversation [Paris Web 2017]
Designing the Conversation [Paris Web 2017]Designing the Conversation [Paris Web 2017]
Designing the Conversation [Paris Web 2017]
 
Exploring Adaptive Interfaces [Generate 2017]
Exploring Adaptive Interfaces [Generate 2017]Exploring Adaptive Interfaces [Generate 2017]
Exploring Adaptive Interfaces [Generate 2017]
 

Recently uploaded

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

The Future of JavaScript (SXSW '07)

  • 1. Andrew & Aaron present: The Future of JavaScript
  • 2. JavaScript 1.6 Based on ECMA-262, edition 3 ● Implemented in Firefox 1.5 ● Added ● ECMAScript for XML (aka E4X; ECMA-357) – Array extras – Array and String generics –
  • 3. Array extras Location methods: ● indexOf() – lastIndexOf() – Iterative methods: ● every() – filter() – forEach() – map() – some() –
  • 4. Iteration examples var ids = [ 1, 2, 3 ]; var els = ids.map( function( i ){ return document.getElementById( 'item_' + i ); } ); for( var i = 0; i < els.length; i++ ){ els[i].style.border = '1px solid'; } and var lis = document.getElementsByTagName( 'li' ); var evenLis = Array.filter( lis, function( li, i ){ return i % 2 == 1; } ); for( var i = 0; i < evenLis.length; i++ ){ evenLis[i].style.background = '#ccc'; }
  • 5. JavaScript 1.7 Based on ECMA-262, edition 3 ● Includes JS1.6 enhancements ● Introduced ● Generators & Iterators – Array comprehensions – Block scope variables – Destructuring assignment –
  • 6. Using JS 1.7 Implemented in Firefox 2 only ● Enable via MIME type: ● <script type="application/javascript;version=1.7"> // code goes here </script> or <script type="application/javascript;version=1.7" » src="/path/to/my.js"></script>
  • 7. Traditional iterative generation for( var i = 1; i < 4; i++ ){ var ul = document.createElement( 'ul' ); for( var j = 1; j <= i; j++ ){ var li = document.createElement( 'li' ); li.appendChild( document.createTextNode( j ) ); ul.appendChild( li ); } document.getElementsByTagName( 'body' » )[0].appendChild( ul ); }
  • 8. Which gives us 1 ● 1 ● 2 ● 1 ● 2 ● 3 ●
  • 9. Optimized iterative generation var $ul = document.createElement( 'ul' ); var $li = document.createElement( 'li' ); for( var i = 1; i < 4; i++ ){ var ul = $ul.cloneNode( true ); for( var j = 1; j <= i; j++ ){ var li = $li.cloneNode( true ); li.appendChild( document.createTextNode( j ) ); ul.appendChild( li ); } document.getElementsByTagName( 'body' » )[0].appendChild( ul ); }
  • 10. Generator-Iterators function $el( tag ){ var el = document.createElement( tag ); while( true ){ yield el.cloneNode( true ); } } var $ul = $el( 'ul' ), $li = $el( 'li' ); for( var i = 1; i < 4; i++ ){ var ul = $ul.next(); for( var j = 1; j <= i; j++ ){ var li = $li.next(); li.appendChild( document.createTextNode( j ) ); ul.appendChild( li ); } document.getElementsByTagName( 'body' » )[0].appendChild( ul ); }
  • 11. Straight Iteration var me = { name: 'Aaron Gustafson', age: 29, 'eye color': 'blue', height: '5ft 11in' }; var it = Iterator( me ); var ul = $ul.next(), li; try{ while( true ){ li = $li.next(); li.appendChild( document.createTextNode( » it.next() ) ); ul.appendChild( li ); } }catch( err if err instanceof StopIteration ){ document.getElementsByTagName( 'body' » )[0].appendChild( ul ); }catch( err ){ alert( 'error: '+err.description ); }
  • 12. Which gives us name,Aaron Gustafson ● age,29 ● eye color,blue ● height,5ft 11in ●
  • 13. Alternation var li = document.getElementsByTagName( 'li' ); for( var i = 0; i < li.length; i++ ){ if( i % 2 == 0 ){ li[i].className = 'even'; } }
  • 14. Generators and array creation function range( start, end ){ for( var i = start; i < end; i++ ){ yield i; } } var li = document.getElementsByTagName( 'li' ); var evens = [i for ( i in range( 0, li.length ) ) » if ( i % 2 ==0 ) ]; for( num in evens ) li[evens[num]].className = 'even';
  • 15. let is the new black Only way we currently get block scope: ● function foo(){ var x = 5; ( function(){ var x = 10; alert( x ); //-> 10 } )(); alert( x ); //-> 5 }
  • 16. let blocks function foo(){ var x = 5; let( x = 10 ){ alert( x ); //-> 10 } alert( x ); //-> 5 } or if you wanna get really crazy ● function foo(){ var x = 5; let( x = x + 5 ){ alert( x ); //-> 10 } alert( x ); //-> 5 }
  • 17. let expressions function foo() { var x = 5; alert( let( x = 10 ) x ); //-> 10 alert( x ); //-> 5 }
  • 18. let in loops for( let i = 0; i < array.length; i++ ) doSomethingWith( array[i] ); alert( i ); //-> undefined or for( let i = 0, subArray; i<array.length; i++ ){ subArray = array[i]; for( let i = 0; i < subArray.length; i++ ) alert( subArray[i] ); }
  • 19. Like a key party in your code Destructuring assignment: ● var a = 1; var b = 2; [a, b]= [b, a]; or var [c, d] = [a, b];
  • 20. Return with greater flexibility We’ve always been able to return arrays ● var result = returnsArray(); var a = result[0]; var b = result[1]; But now ● var [a,b] = returnsArray(); or even var [,b] = returnsArray();
  • 21. That’s not all, let’s play with JSON var me = { name: 'Aaron Gustafson', age: 29, 'eye color': 'blue', height: '5ft 11in' }; var ul = $ul.next(); for( let [ key, value ] in me ){ let li = $li.next(); li.appendChild( document.createTextNode( 'Key: ' + key + ', Value: ' + value ) ); ul.appendChild( li ); } document.getElementsByTagName( 'body' » )[0].appendChild( ul );
  • 22. Resulting in Key: name, Value: Aaron Gustafson ● Key: age, Value: 29 ● Key: eye color, Value: blue ● Key: height, Value: 5ft 11in ●
  • 23. Or iterate safely over an Object Object.prototype.HAHAHA = "I AM THE HASH DESTRUCTOR"; for( let [ key, value ] in me ) alert( key ); /* 'name', 'age', 'eye color', 'height', 'HAHAHA' */ function SafeHashIterator( hash, keysOnly ){ for( let [key, value] in hash ){ if( !hash.hasOwnProperty( key ) ) continue; yield keysOnly ? key : [key, value]; } throw StopIteration; } for( let [key, value] in SafeHashIterator( me ) ) alert( key ); // 'name', 'age', 'eye color', 'height'
  • 24. So why should I care?