SlideShare a Scribd company logo
1 of 53
Download to read offline
JavaScript 1.5 to 2.0
   John Resig (ejohn.org)
    Mozilla Corporation
The Big Picture
                     ECMAScript 3


JavaScript 1.5   ActionScript 2      JScript        Etc.


SpiderMonkey         AVM          JScript Engine KJS (Apple)


   Rhino                                           Opera
Jav
          aS




1999
             crip
                 t1
                    .5
       Jav




2005
          aS
             crip
                 t1
                    .6
       Jav

2006
          aS
             crip
                 t1
                    .7
       Jav
          aS
2008

             c
       Jav ript
          aS        1.8
             cr
                ipt
       Ja
                              Path to JavaScript 2




                    1.9
          va
2009




             Sc
                 ri
                    pt
                          2
The JavaScript Language
    Current:
āœ¦
    JavaScript 1.5 (Firefox 1, ES3)
    JavaScript 1.6 (Firefox 1.5)
āœ¦

    JavaScript 1.7 (Firefox 2)
āœ¦

    JavaScipt 1.8 (Firefox 3)
āœ¦

    JavaScript 1.9 (Firefox 3.1)
āœ¦

    JavaScript 2 (Firefox 4, ES4)
āœ¦
JavaScript 1.5
    Getters and Setters
āœ¦
    āœ¦ Extra power over properties
    āœ¦ Two powerful uses:
      āœ¦ Private data access
      āœ¦ Lazy-loading data

    var n = ā€œJohnā€;
āœ¦
    var obj = {
      get name(){ return n; },
      set name(value){ n = value; }
    };
    obj.name = ā€œTedā€;
    obj.name == ā€œTedā€ // true
Getters and Setters
    var n = ā€œJohnā€;
āœ¦
    var obj = {};
    obj.__deļ¬neGetter__(ā€œnameā€,
     function(){ return n; });
    obj.__deļ¬neSetter__(ā€œnameā€,
     function(value){ n = value; });
    obj.name = ā€œTedā€;
    obj.name == ā€œTedā€; // true
    obj.__lookupGetter__(ā€œnameā€)
āœ¦
    // => function(){ return n; }
    // __lookupSetter__ too!
Lazy-Loading Data
    var pixelsDone;
āœ¦
    data.__deļ¬neGetter__(ā€pixelsā€, function(){
      if ( pixelsDone )
        return pixelsDone;
      pixelsDone = [];
      for ( var i = 0; i < pixels.length; i += 4 ){
        pixelsDone.push( p.color(...) );
      }
      return pixelsDone;
    });
    obj.pixels[3]
āœ¦
JavaScript 1.6
    Array Extras
āœ¦
    āœ¦ indexOf / lastIndexOf
      [0,1,2].indexOf(1) == 1
    āœ¦ every / ļ¬lter / some
      [0,1,2].every(function(val){ return val >
      0; }); // false
    āœ¦ map
      [0,1,2].map(function(val){return val + 1;});
      // [1,2,3]
    āœ¦ forEach
      [0,1,2].forEach(function(val,index){});
JavaScript 1.7
    Generators and Iterators
āœ¦
    āœ¦ Lazy-load data
      āœ¦ Database querying
    āœ¦ Threading
      http://www.neilmix.com/2007/02/07/
      threading-in-javascript-17/
Generators and Iterators
    function ļ¬b() {
āœ¦
      var i = 0, j = 1;
      while (true) {
        yield i;
        var t = i;
        i = j; j += t;
      }
    }
    var g = ļ¬b();
    for ( var i in g ) {
      document.write(i + ā€œ<br>nā€);
      if ( i > 100 ) break;
    }
let
    Block-level statements
āœ¦

    for ( let i = 0; i < 10; i++ ) { }
āœ¦

    while ( true ) { let test = 5; }
āœ¦

    let (test = 5) {
āœ¦
      function stuļ¬€(){ return test; }
    }
    { let test = 5;
āœ¦
      { let test = 6; print(test);}
      print(test); }
Array Comprehension
    [i for ( let i = 0; i < 3; i++ )]
āœ¦
    // => [0, 1, 2]
    function range(begin, end) {
āœ¦
      for (let i = begin; i < end; ++i) {
        yield i;
      }
    }
    [i for each (i in range(0, 3))]
Destructuring
    var [newA, newB] = [a, b];
āœ¦

    var newA = a, newB = b;
āœ¦

    [a, b] = [b, a]
āœ¦

    function test(){ return [0, 1]; }
āœ¦
    let [a, b] = test();
    var [, c] = test();
    var {name: name} = {name: ā€œJohnā€}
āœ¦
    name == ā€œJohnā€
    var {name} = {name: ā€œJohnā€}
āœ¦
JavaScript 1.8
    Mostly a bug ļ¬x release
āœ¦

    Expression Closures
āœ¦
    function(x){ return x * x; }
    function(x) x * x;
    Generator Expressions
āœ¦
    function val_iter(obj) {
      return (obj[x] for (x in obj));
    }
    for ( let value in val_iter(obj) ) { ... }
reduce
    Great for summing or concating
āœ¦
    [x for ( x in 100 )]
     .reduce(function(a,b) a+b);
    [[...],[...]]
āœ¦
     .reduce(function(a,b){ a.concat(b);}, [])
    reduceRight
āœ¦
JavaScript 1.9
    Merge object properties:
āœ¦
    Object.extend( baseObj, otherObj )
    Function.prototype.bind()
āœ¦
    fn.bind(someThis)
    ā€œ string ā€.trim()
āœ¦
    // => ā€œstringā€
    mozilla.hashcode(someObj)
āœ¦
    // => 1234 (unique ID)
deļ¬neProperty
    Object.deļ¬neProperty(obj, name, value,
āœ¦
    types)
    var obj = {};
āœ¦
    Object.deļ¬neProperty(obj, ā€œnameā€, ā€œJohnā€,
     Object.NOT_WRITABLE |
     Object.NOT_DELETABLE);
    obj.name = ā€œTestā€;
    obj.name == ā€œJohnā€;
    delete obj.name
    obj.name == ā€œJohnā€;
JSON
    mozilla.JSON.parse(ā€œ{name:ā€™Johnā€™}ā€)
āœ¦
    // => {name: ā€˜Johnā€™}
    mozilla.JSON.serialize({name:ā€™Johnā€™})
āœ¦
    // => ā€œ{name:ā€™Johnā€™}ā€
Catchalls
    var props = {};
āœ¦
    var obj = {
      test: true,
      get *(name){
        return props[name];
      },
      set *(name, value){
        props[name] = value;
      }
    }
    obj.__deļ¬neGetter_(ā€œā€, function(){})
āœ¦
JavaScript 2 Goals
    Backwards Compatible
āœ¦

    Suitable to developing large systems
āœ¦

    Allow for reusable libraries
āœ¦

    Merge previous eļ¬€orts (ActionScript)
āœ¦

    Fix ECMAScript 3 bugs
āœ¦

    Keep it usable for small programs
āœ¦
Features
    Classes and Interfaces
āœ¦

    Packages and Namespaces
āœ¦

    Type Annotations
āœ¦

    Strict Veriļ¬cation
āœ¦

    Optimization
āœ¦

    Syntax Shortcuts
āœ¦

    Iterators and Generators
āœ¦

    Self-hosting
āœ¦
The Direction
                         ECMAScript 4


JavaScript 2         ActionScript 4      JScript       Etc.


                                        Screaming
               Tamarin                              KJS (Apple)
                                         Monkey


                                                      Opera
Tamarin
    Tamarin
āœ¦
    āœ¦ New Virtual Machine from Adobe
    āœ¦ Perfect for ActionScript
      āœ¦ (a mutant cousin of JavaScript 2)

    The Three Monkeys:
āœ¦
    āœ¦ ActionMonkey
    āœ¦ ScreamingMonkey
    āœ¦ IronMonkey
Three Monkies
    ActionMonkey
āœ¦
    āœ¦ Integrating Tamarin into SpiderMonkey
    āœ¦ Powering Firefox 4 (?) + JavaScript 2

    ScreamingMonkey
āœ¦
    āœ¦ Forcing Tamarin into Internet Explorer
    āœ¦ (Kicking and screaming?)

    IronMonkey
āœ¦
    āœ¦ Bringing Python + Ruby to Tamarin
Classes
Classes
    class Programmer {
āœ¦
       var name;
       var city = ā€œBoston, MAā€;
       const interest = ā€œcomputersā€;
       function work() {}
    }
    var p = new Programmer;
āœ¦
    p.name = ā€œJohnā€;
    p.work();
    p.work.apply( someotherp );
    p.interest = ā€œscienceā€; // Error
Dynamic Classes
    dynamic class Programmer {
āœ¦
      var name;
      var city = ā€œBoston, MAā€;
      const interest = ā€œcomputersā€;
      function work() {}
    }
    var p = new Programmer;
āœ¦
    p.lastName = ā€œResigā€;
    for ( var i in p )
       alert( i );
    // alert( ā€œResigā€ );
Getters and Setters
    class Programmer {
āœ¦
       var _name;
       function get name(){ return _name; }
       function set name(value){
         _name = value + ā€œ Resigā€;
       }
    }
    var p = new Programmer;
āœ¦
    p.name = ā€œJohnā€;
    alert( p.name );
    // ā€œJohn Resigā€
Catch-Alls
    dynamic class Programmer {
āœ¦
      meta function get(name) { ... }
      meta function set(name, value) {
        alert(ā€œSetting ā€œ + name + ā€œ to ā€œ + value);
      }
    }
    var p = new Programmer
āœ¦
    p.name = ā€œJohnā€;
    // alert(ā€œSetting name to Johnā€);
Inheritance
    class Artist {
āœ¦
       function draw() { alert(ā€œDrawing!ā€); }
    }
    class Designer extends Artist {
       override function draw() {
         alert(ā€œDesigning!ā€);
       }
    }
    var d = new Designer
āœ¦
    d.draw();
    // alert(ā€œDesigning!ā€);
Inheritance (cont.)
    ā€˜ļ¬nalā€™ methods canā€™t be overriden
āœ¦

    class Artist {
āœ¦
       ļ¬nal function draw() {alert(ā€œDrawing!ā€);}
    }
    class Designer extends Artist {
       // ERROR: Canā€™t override draw!
       override function draw() {
          alert(ā€œDesigning!ā€);
       }
    }
Inheritance (cont.)
    ā€˜ļ¬nalā€™ classes canā€™t be inherited from
āœ¦

    ļ¬nal class Artist {
āœ¦
      function draw() { alert(ā€œDrawing!ā€); }
    }

    // ERROR: Canā€™t inherit from Artist
    class Designer extends Artist {
       override function draw() {
         alert(ā€œDesigning!ā€);
       }
    }
Metaclass
    Provide global functions and properties on
āœ¦
    a class object
    class Users {
āœ¦
       static function ļ¬nd( name ) {
         // ...
       }
    }
    Users.ļ¬nd( ā€œJohnā€ );
āœ¦
Interfaces
    Verify that a class implements another
āœ¦

    class Artist {
āœ¦
       function draw();
    }

    class Designer implements Artist {
       function draw() { alert(ā€œDesigning!ā€); }
    }
    if ( Designer is Artist )
āœ¦
       alert(ā€œDesigners are Artists!ā€);
Types
Types
    Types are broken down into:
āœ¦
    āœ¦ string
    āœ¦ double (ECMAScript 3-style Number)
    āœ¦ boolean
Type Annotations
    var name : string = ā€œJohnā€;
āœ¦

    let x : double = 5.3;
āœ¦

    function stuļ¬€( x: string, obj: Object ) :
āœ¦
    boolean {}
Function Types
    Only return speciļ¬c types:
āœ¦
    function isValid() : boolean { }
    Only be used on certain objects types:
āœ¦
    function every( this: Array ) {
       for ( var i = 0; i < this.length; i++ )
          alert( this[i] );
    }
    every.call( [0,1,2] );
    // alert(0); alert(1); alert(2);
    every.call({a: ā€œbā€});
    // ERROR
Rest Arguments
    function stuļ¬€( name, ...values ){
āœ¦
      alert( values.length );
    }
    stuļ¬€( ā€œJohnā€, 1, 2, 3, 4 );
āœ¦
    // alert( 4 );
    function stuļ¬€( name : string, ...values : [double] ) : void
āœ¦
    {
      alert( values.length );
    }

    var array = [1,2,3,4];
āœ¦
    stuļ¬€( ā€œJohnā€, ...array );
Union and Any Types
    var test : (string, double) = ā€œtestā€;
āœ¦
    test = 3;
    test = {}; // ERROR
    These are equivalent:
āœ¦
    āœ¦ var test : * = ā€œtestā€;
    āœ¦ var test = ā€œtestā€;
Type Deļ¬nitions
    type Point = { x: double, y: double };
āœ¦

    var p : Point = { x: 3.0, y: 24.0 };
āœ¦
Nullability
    Prevent variables from accepting null
āœ¦
    values
    var name : * = ā€œJohnā€;
āœ¦

    var name : string! = ā€œJohnā€;
āœ¦
    name = ā€œTedā€;
    name = null; // ERROR
    function test( name: string? ) {
āœ¦
      alert( name );
    }
Initialization
    class User {
āœ¦
       var name : string!; // Must be initialized
       function User( n ) : name = n {
          // ...
       }
    }
ā€œlikeā€
    type Point = { x: double, y: double };
āœ¦

    if ( { x: 3, y: 5 } like Point )
āœ¦
       alert( ā€œThat looks like a point to me!ā€ );
    if ( !({ x: 3 } like Point) )
āœ¦
       alert( ā€œNot a point!ā€ );
    // Loop over array-like things:
āœ¦
    function every( a: like { length: double } ) {
       for ( var i = 0; i < a.length; i++ )
         alert( a[i] );
    }
Parameterized Types
    var m: Map.<string, *>;
āœ¦

    class Point.<T> {
āœ¦
       var x: T, y: T;
    }
    var p = new Point.<double>;
āœ¦
    p.x = 3.0;
    p.y = 5.0;
Structure
Namespaces
    namespace extra = ā€œextraā€;
āœ¦

    Pre-deļ¬ned namespaces:
āœ¦
    āœ¦ __ES4__
      āœ¦ intrinsic
      āœ¦ iterator
      āœ¦ meta

    Namespaced variables:
āœ¦
    iteration::StopIteration
    intrinsic::readFile
Multimethods
    generic function intersect(s1, s2);
āœ¦
    generic function intersect(s1: Shape, s2: Shape ) {
      // ...
    }
    generic function intersect(s1: Rect, s2: Rect ) {
      // ...
    }
    generic function test(a: Object?, b...
āœ¦

    generic function test(a: Object!
āœ¦
Iteration
    class Fib {
āœ¦
       private var a=0, b=1;

        iterator function get(deep:boolean = false) : IteratorType.<double>
           this

        public function next(): double {
          if ( b > 100 )
              throw iterator::StopIteration;
          [a,b] = [b,a+b];
          return a;
        }
    }

    for ( let i in new Fib )
āœ¦
      alert( i );
For .. Each
    For each loops through values
āœ¦

    let s = ā€œā€;
āœ¦
    for each ( let n in [ā€œaā€,ā€bā€,ā€cā€] )
        s += n;
    alert(s);
    // ā€œabcā€
Self-Hosting
Map.es
    The reference implementationā€™s classes are
āœ¦
    written in ECMAScript
    package
āœ¦
    {
      use namespace intrinsic;
      use default namespace public;
      intrinsic class Map.<K,V>
      {
        static const length = 2;
        function Map(equals=intrinsic::===, hashcode=intrinsic::hashcode)
            : equals = equals
            , hashcode = hashcode
            , element_count = 0
        {
        }
        // ...
    }
More Info
    ECMAScript 4 Progress:
āœ¦
    http://spreadsheets.google.com/ccc?key=pFIHldY_CkszsFxMkQOReAQ&hl=en


    ECMAScript 4 White Paper Overview:
āœ¦
    http://www.ecmascript.org/es4/spec/overview.pdf

    Blogging:
āœ¦
    http://ejohn.org/

More Related Content

What's hot

Remy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQueryRemy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQuerydeimos
Ā 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQueryRemy Sharp
Ā 
Joe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand DwrJoe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand Dwrdeimos
Ā 
Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQueryRemy Sharp
Ā 
The Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J QueryThe Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J QueryQConLondon2008
Ā 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreRemy Sharp
Ā 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Remy Sharp
Ā 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQueryAngel Ruiz
Ā 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingDoug Neiner
Ā 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009Remy Sharp
Ā 
An in-depth look at jQuery
An in-depth look at jQueryAn in-depth look at jQuery
An in-depth look at jQueryPaul Bakaus
Ā 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuerySudar Muthu
Ā 
JQuery in Seaside
JQuery in SeasideJQuery in Seaside
JQuery in SeasideESUG
Ā 
jQuery: Events, Animation, Ajax
jQuery: Events, Animation, AjaxjQuery: Events, Animation, Ajax
jQuery: Events, Animation, AjaxConstantin Titarenko
Ā 
Mulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitMulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitRebecca Murphey
Ā 

What's hot (20)

Remy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQueryRemy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQuery
Ā 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQuery
Ā 
Joe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand DwrJoe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand Dwr
Ā 
Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQuery
Ā 
The Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J QueryThe Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J Query
Ā 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
Ā 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
Ā 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
Ā 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
Ā 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and Bling
Ā 
HTML,CSS Next
HTML,CSS NextHTML,CSS Next
HTML,CSS Next
Ā 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
Ā 
An in-depth look at jQuery
An in-depth look at jQueryAn in-depth look at jQuery
An in-depth look at jQuery
Ā 
Jquery ui
Jquery uiJquery ui
Jquery ui
Ā 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuery
Ā 
jQuery
jQueryjQuery
jQuery
Ā 
JQuery in Seaside
JQuery in SeasideJQuery in Seaside
JQuery in Seaside
Ā 
jQuery: Events, Animation, Ajax
jQuery: Events, Animation, AjaxjQuery: Events, Animation, Ajax
jQuery: Events, Animation, Ajax
Ā 
Intro to HTML5
Intro to HTML5Intro to HTML5
Intro to HTML5
Ā 
Mulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitMulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development Toolkit
Ā 

Similar to JavaScript 1.5 to 2.0 (TomTom)

Tamarin and ECMAScript 4
Tamarin and ECMAScript 4Tamarin and ECMAScript 4
Tamarin and ECMAScript 4jeresig
Ā 
Tamarin And Ecmascript 4
Tamarin And Ecmascript 4Tamarin And Ecmascript 4
Tamarin And Ecmascript 4elliando dias
Ā 
The Future of JavaScript (Ajax Exp '07)
The Future of JavaScript (Ajax Exp '07)The Future of JavaScript (Ajax Exp '07)
The Future of JavaScript (Ajax Exp '07)jeresig
Ā 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptCaridy Patino
Ā 
What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?Christophe Porteneuve
Ā 
History of jQuery
History of jQueryHistory of jQuery
History of jQueryjeresig
Ā 
Cappuccino @ JSConf 2009
Cappuccino @ JSConf 2009Cappuccino @ JSConf 2009
Cappuccino @ JSConf 2009tolmasky
Ā 
Groovy and Grails talk
Groovy and Grails talkGroovy and Grails talk
Groovy and Grails talkdesistartups
Ā 
Functional Javascript
Functional JavascriptFunctional Javascript
Functional Javascriptguest4d57e6
Ā 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6Solution4Future
Ā 
javascript teach
javascript teachjavascript teach
javascript teachguest3732fa
Ā 
JSBootcamp_White
JSBootcamp_WhiteJSBootcamp_White
JSBootcamp_Whiteguest3732fa
Ā 
JavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best PracticesJavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best PracticesSiarhei Barysiuk
Ā 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Troy Miles
Ā 
LISA QooxdooTutorial Slides
LISA QooxdooTutorial SlidesLISA QooxdooTutorial Slides
LISA QooxdooTutorial SlidesTobias Oetiker
Ā 
OO JS for AS3 Devs
OO JS for AS3 DevsOO JS for AS3 Devs
OO JS for AS3 DevsJason Hanson
Ā 
From Javascript To Haskell
From Javascript To HaskellFrom Javascript To Haskell
From Javascript To Haskellujihisa
Ā 

Similar to JavaScript 1.5 to 2.0 (TomTom) (20)

Tamarin and ECMAScript 4
Tamarin and ECMAScript 4Tamarin and ECMAScript 4
Tamarin and ECMAScript 4
Ā 
Tamarin And Ecmascript 4
Tamarin And Ecmascript 4Tamarin And Ecmascript 4
Tamarin And Ecmascript 4
Ā 
The Future of JavaScript (Ajax Exp '07)
The Future of JavaScript (Ajax Exp '07)The Future of JavaScript (Ajax Exp '07)
The Future of JavaScript (Ajax Exp '07)
Ā 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
Ā 
What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?
Ā 
History of jQuery
History of jQueryHistory of jQuery
History of jQuery
Ā 
Cappuccino @ JSConf 2009
Cappuccino @ JSConf 2009Cappuccino @ JSConf 2009
Cappuccino @ JSConf 2009
Ā 
Groovy and Grails talk
Groovy and Grails talkGroovy and Grails talk
Groovy and Grails talk
Ā 
Functional Javascript
Functional JavascriptFunctional Javascript
Functional Javascript
Ā 
Javascript status 2016
Javascript status 2016Javascript status 2016
Javascript status 2016
Ā 
JavaScript Core
JavaScript CoreJavaScript Core
JavaScript Core
Ā 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
Ā 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
Ā 
javascript teach
javascript teachjavascript teach
javascript teach
Ā 
JSBootcamp_White
JSBootcamp_WhiteJSBootcamp_White
JSBootcamp_White
Ā 
JavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best PracticesJavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best Practices
Ā 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
Ā 
LISA QooxdooTutorial Slides
LISA QooxdooTutorial SlidesLISA QooxdooTutorial Slides
LISA QooxdooTutorial Slides
Ā 
OO JS for AS3 Devs
OO JS for AS3 DevsOO JS for AS3 Devs
OO JS for AS3 Devs
Ā 
From Javascript To Haskell
From Javascript To HaskellFrom Javascript To Haskell
From Javascript To Haskell
Ā 

More from jeresig

Does Coding Every Day Matter?
Does Coding Every Day Matter?Does Coding Every Day Matter?
Does Coding Every Day Matter?jeresig
Ā 
Accidentally Becoming a Digital Librarian
Accidentally Becoming a Digital LibrarianAccidentally Becoming a Digital Librarian
Accidentally Becoming a Digital Librarianjeresig
Ā 
2014: John's Favorite Thing (Neo4j)
2014: John's Favorite Thing (Neo4j)2014: John's Favorite Thing (Neo4j)
2014: John's Favorite Thing (Neo4j)jeresig
Ā 
Computer Vision as Art Historical Investigation
Computer Vision as Art Historical InvestigationComputer Vision as Art Historical Investigation
Computer Vision as Art Historical Investigationjeresig
Ā 
Hacking Art History
Hacking Art HistoryHacking Art History
Hacking Art Historyjeresig
Ā 
Using JS to teach JS at Khan Academy
Using JS to teach JS at Khan AcademyUsing JS to teach JS at Khan Academy
Using JS to teach JS at Khan Academyjeresig
Ā 
Applying Computer Vision to Art History
Applying Computer Vision to Art HistoryApplying Computer Vision to Art History
Applying Computer Vision to Art Historyjeresig
Ā 
NYARC 2014: Frick/Zeri Results
NYARC 2014: Frick/Zeri ResultsNYARC 2014: Frick/Zeri Results
NYARC 2014: Frick/Zeri Resultsjeresig
Ā 
EmpireJS: Hacking Art with Node js and Image Analysis
EmpireJS: Hacking Art with Node js and Image AnalysisEmpireJS: Hacking Art with Node js and Image Analysis
EmpireJS: Hacking Art with Node js and Image Analysisjeresig
Ā 
Applying Computer Vision to Art History
Applying Computer Vision to Art HistoryApplying Computer Vision to Art History
Applying Computer Vision to Art Historyjeresig
Ā 
JavaScript Libraries (Ajax Exp 2006)
JavaScript Libraries (Ajax Exp 2006)JavaScript Libraries (Ajax Exp 2006)
JavaScript Libraries (Ajax Exp 2006)jeresig
Ā 
Introduction to jQuery (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)Introduction to jQuery (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)jeresig
Ā 
jQuery Recommendations to the W3C (2011)
jQuery Recommendations to the W3C (2011)jQuery Recommendations to the W3C (2011)
jQuery Recommendations to the W3C (2011)jeresig
Ā 
jQuery Open Source Process (RIT 2011)
jQuery Open Source Process (RIT 2011)jQuery Open Source Process (RIT 2011)
jQuery Open Source Process (RIT 2011)jeresig
Ā 
jQuery Open Source Process (Knight Foundation 2011)
jQuery Open Source Process (Knight Foundation 2011)jQuery Open Source Process (Knight Foundation 2011)
jQuery Open Source Process (Knight Foundation 2011)jeresig
Ā 
jQuery Mobile
jQuery MobilejQuery Mobile
jQuery Mobilejeresig
Ā 
jQuery Open Source (Fronteer 2011)
jQuery Open Source (Fronteer 2011)jQuery Open Source (Fronteer 2011)
jQuery Open Source (Fronteer 2011)jeresig
Ā 
Holistic JavaScript Performance
Holistic JavaScript PerformanceHolistic JavaScript Performance
Holistic JavaScript Performancejeresig
Ā 
New Features Coming in Browsers (RIT '09)
New Features Coming in Browsers (RIT '09)New Features Coming in Browsers (RIT '09)
New Features Coming in Browsers (RIT '09)jeresig
Ā 
Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)jeresig
Ā 

More from jeresig (20)

Does Coding Every Day Matter?
Does Coding Every Day Matter?Does Coding Every Day Matter?
Does Coding Every Day Matter?
Ā 
Accidentally Becoming a Digital Librarian
Accidentally Becoming a Digital LibrarianAccidentally Becoming a Digital Librarian
Accidentally Becoming a Digital Librarian
Ā 
2014: John's Favorite Thing (Neo4j)
2014: John's Favorite Thing (Neo4j)2014: John's Favorite Thing (Neo4j)
2014: John's Favorite Thing (Neo4j)
Ā 
Computer Vision as Art Historical Investigation
Computer Vision as Art Historical InvestigationComputer Vision as Art Historical Investigation
Computer Vision as Art Historical Investigation
Ā 
Hacking Art History
Hacking Art HistoryHacking Art History
Hacking Art History
Ā 
Using JS to teach JS at Khan Academy
Using JS to teach JS at Khan AcademyUsing JS to teach JS at Khan Academy
Using JS to teach JS at Khan Academy
Ā 
Applying Computer Vision to Art History
Applying Computer Vision to Art HistoryApplying Computer Vision to Art History
Applying Computer Vision to Art History
Ā 
NYARC 2014: Frick/Zeri Results
NYARC 2014: Frick/Zeri ResultsNYARC 2014: Frick/Zeri Results
NYARC 2014: Frick/Zeri Results
Ā 
EmpireJS: Hacking Art with Node js and Image Analysis
EmpireJS: Hacking Art with Node js and Image AnalysisEmpireJS: Hacking Art with Node js and Image Analysis
EmpireJS: Hacking Art with Node js and Image Analysis
Ā 
Applying Computer Vision to Art History
Applying Computer Vision to Art HistoryApplying Computer Vision to Art History
Applying Computer Vision to Art History
Ā 
JavaScript Libraries (Ajax Exp 2006)
JavaScript Libraries (Ajax Exp 2006)JavaScript Libraries (Ajax Exp 2006)
JavaScript Libraries (Ajax Exp 2006)
Ā 
Introduction to jQuery (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)Introduction to jQuery (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)
Ā 
jQuery Recommendations to the W3C (2011)
jQuery Recommendations to the W3C (2011)jQuery Recommendations to the W3C (2011)
jQuery Recommendations to the W3C (2011)
Ā 
jQuery Open Source Process (RIT 2011)
jQuery Open Source Process (RIT 2011)jQuery Open Source Process (RIT 2011)
jQuery Open Source Process (RIT 2011)
Ā 
jQuery Open Source Process (Knight Foundation 2011)
jQuery Open Source Process (Knight Foundation 2011)jQuery Open Source Process (Knight Foundation 2011)
jQuery Open Source Process (Knight Foundation 2011)
Ā 
jQuery Mobile
jQuery MobilejQuery Mobile
jQuery Mobile
Ā 
jQuery Open Source (Fronteer 2011)
jQuery Open Source (Fronteer 2011)jQuery Open Source (Fronteer 2011)
jQuery Open Source (Fronteer 2011)
Ā 
Holistic JavaScript Performance
Holistic JavaScript PerformanceHolistic JavaScript Performance
Holistic JavaScript Performance
Ā 
New Features Coming in Browsers (RIT '09)
New Features Coming in Browsers (RIT '09)New Features Coming in Browsers (RIT '09)
New Features Coming in Browsers (RIT '09)
Ā 
Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)
Ā 

Recently uploaded

Call Girls Jp Nagar Just Call šŸ‘— 7737669865 šŸ‘— Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call šŸ‘— 7737669865 šŸ‘— Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call šŸ‘— 7737669865 šŸ‘— Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call šŸ‘— 7737669865 šŸ‘— Top Class Call Girl Service Bang...amitlee9823
Ā 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLSeo
Ā 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Neil Kimberley
Ā 
Falcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to ProsperityFalcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to Prosperityhemanthkumar470700
Ā 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1kcpayne
Ā 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfAdmir Softic
Ā 
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...allensay1
Ā 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Dave Litwiller
Ā 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsP&CO
Ā 
Call Girls In DLf Gurgaon āž„99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon āž„99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon āž„99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon āž„99902@11544 ( Best price)100% Genuine Escort In 24...lizamodels9
Ā 
Business Model Canvas (BMC)- A new venture concept
Business Model Canvas (BMC)-  A new venture conceptBusiness Model Canvas (BMC)-  A new venture concept
Business Model Canvas (BMC)- A new venture conceptP&CO
Ā 
Russian Call Girls In Gurgaon ā¤ļø8448577510 āŠ¹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ā¤ļø8448577510 āŠ¹Best Escorts Service In 24/7 Delh...Russian Call Girls In Gurgaon ā¤ļø8448577510 āŠ¹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ā¤ļø8448577510 āŠ¹Best Escorts Service In 24/7 Delh...lizamodels9
Ā 
Call Girls Kengeri Satellite Town Just Call šŸ‘— 7737669865 šŸ‘— Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call šŸ‘— 7737669865 šŸ‘— Top Class Call Gir...Call Girls Kengeri Satellite Town Just Call šŸ‘— 7737669865 šŸ‘— Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call šŸ‘— 7737669865 šŸ‘— Top Class Call Gir...amitlee9823
Ā 
Falcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in indiaFalcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in indiaFalcon Invoice Discounting
Ā 
RSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataRSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataExhibitors Data
Ā 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayNZSG
Ā 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentationuneakwhite
Ā 
šŸ‘‰Chandigarh Call Girls šŸ‘‰9878799926šŸ‘‰Just CallšŸ‘‰Chandigarh Call Girl In Chandiga...
šŸ‘‰Chandigarh Call Girls šŸ‘‰9878799926šŸ‘‰Just CallšŸ‘‰Chandigarh Call Girl In Chandiga...šŸ‘‰Chandigarh Call Girls šŸ‘‰9878799926šŸ‘‰Just CallšŸ‘‰Chandigarh Call Girl In Chandiga...
šŸ‘‰Chandigarh Call Girls šŸ‘‰9878799926šŸ‘‰Just CallšŸ‘‰Chandigarh Call Girl In Chandiga...rajveerescorts2022
Ā 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Roland Driesen
Ā 

Recently uploaded (20)

Call Girls Jp Nagar Just Call šŸ‘— 7737669865 šŸ‘— Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call šŸ‘— 7737669865 šŸ‘— Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call šŸ‘— 7737669865 šŸ‘— Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call šŸ‘— 7737669865 šŸ‘— Top Class Call Girl Service Bang...
Ā 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
Ā 
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabiunwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
Ā 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023
Ā 
Falcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to ProsperityFalcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to Prosperity
Ā 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1
Ā 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Ā 
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Ā 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Ā 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and pains
Ā 
Call Girls In DLf Gurgaon āž„99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon āž„99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon āž„99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon āž„99902@11544 ( Best price)100% Genuine Escort In 24...
Ā 
Business Model Canvas (BMC)- A new venture concept
Business Model Canvas (BMC)-  A new venture conceptBusiness Model Canvas (BMC)-  A new venture concept
Business Model Canvas (BMC)- A new venture concept
Ā 
Russian Call Girls In Gurgaon ā¤ļø8448577510 āŠ¹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ā¤ļø8448577510 āŠ¹Best Escorts Service In 24/7 Delh...Russian Call Girls In Gurgaon ā¤ļø8448577510 āŠ¹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ā¤ļø8448577510 āŠ¹Best Escorts Service In 24/7 Delh...
Ā 
Call Girls Kengeri Satellite Town Just Call šŸ‘— 7737669865 šŸ‘— Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call šŸ‘— 7737669865 šŸ‘— Top Class Call Gir...Call Girls Kengeri Satellite Town Just Call šŸ‘— 7737669865 šŸ‘— Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call šŸ‘— 7737669865 šŸ‘— Top Class Call Gir...
Ā 
Falcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in indiaFalcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in india
Ā 
RSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataRSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors Data
Ā 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 May
Ā 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentation
Ā 
šŸ‘‰Chandigarh Call Girls šŸ‘‰9878799926šŸ‘‰Just CallšŸ‘‰Chandigarh Call Girl In Chandiga...
šŸ‘‰Chandigarh Call Girls šŸ‘‰9878799926šŸ‘‰Just CallšŸ‘‰Chandigarh Call Girl In Chandiga...šŸ‘‰Chandigarh Call Girls šŸ‘‰9878799926šŸ‘‰Just CallšŸ‘‰Chandigarh Call Girl In Chandiga...
šŸ‘‰Chandigarh Call Girls šŸ‘‰9878799926šŸ‘‰Just CallšŸ‘‰Chandigarh Call Girl In Chandiga...
Ā 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ā 

JavaScript 1.5 to 2.0 (TomTom)

  • 1. JavaScript 1.5 to 2.0 John Resig (ejohn.org) Mozilla Corporation
  • 2. The Big Picture ECMAScript 3 JavaScript 1.5 ActionScript 2 JScript Etc. SpiderMonkey AVM JScript Engine KJS (Apple) Rhino Opera
  • 3. Jav aS 1999 crip t1 .5 Jav 2005 aS crip t1 .6 Jav 2006 aS crip t1 .7 Jav aS 2008 c Jav ript aS 1.8 cr ipt Ja Path to JavaScript 2 1.9 va 2009 Sc ri pt 2
  • 4. The JavaScript Language Current: āœ¦ JavaScript 1.5 (Firefox 1, ES3) JavaScript 1.6 (Firefox 1.5) āœ¦ JavaScript 1.7 (Firefox 2) āœ¦ JavaScipt 1.8 (Firefox 3) āœ¦ JavaScript 1.9 (Firefox 3.1) āœ¦ JavaScript 2 (Firefox 4, ES4) āœ¦
  • 5. JavaScript 1.5 Getters and Setters āœ¦ āœ¦ Extra power over properties āœ¦ Two powerful uses: āœ¦ Private data access āœ¦ Lazy-loading data var n = ā€œJohnā€; āœ¦ var obj = { get name(){ return n; }, set name(value){ n = value; } }; obj.name = ā€œTedā€; obj.name == ā€œTedā€ // true
  • 6. Getters and Setters var n = ā€œJohnā€; āœ¦ var obj = {}; obj.__deļ¬neGetter__(ā€œnameā€, function(){ return n; }); obj.__deļ¬neSetter__(ā€œnameā€, function(value){ n = value; }); obj.name = ā€œTedā€; obj.name == ā€œTedā€; // true obj.__lookupGetter__(ā€œnameā€) āœ¦ // => function(){ return n; } // __lookupSetter__ too!
  • 7. Lazy-Loading Data var pixelsDone; āœ¦ data.__deļ¬neGetter__(ā€pixelsā€, function(){ if ( pixelsDone ) return pixelsDone; pixelsDone = []; for ( var i = 0; i < pixels.length; i += 4 ){ pixelsDone.push( p.color(...) ); } return pixelsDone; }); obj.pixels[3] āœ¦
  • 8. JavaScript 1.6 Array Extras āœ¦ āœ¦ indexOf / lastIndexOf [0,1,2].indexOf(1) == 1 āœ¦ every / ļ¬lter / some [0,1,2].every(function(val){ return val > 0; }); // false āœ¦ map [0,1,2].map(function(val){return val + 1;}); // [1,2,3] āœ¦ forEach [0,1,2].forEach(function(val,index){});
  • 9. JavaScript 1.7 Generators and Iterators āœ¦ āœ¦ Lazy-load data āœ¦ Database querying āœ¦ Threading http://www.neilmix.com/2007/02/07/ threading-in-javascript-17/
  • 10. Generators and Iterators function ļ¬b() { āœ¦ var i = 0, j = 1; while (true) { yield i; var t = i; i = j; j += t; } } var g = ļ¬b(); for ( var i in g ) { document.write(i + ā€œ<br>nā€); if ( i > 100 ) break; }
  • 11. let Block-level statements āœ¦ for ( let i = 0; i < 10; i++ ) { } āœ¦ while ( true ) { let test = 5; } āœ¦ let (test = 5) { āœ¦ function stuļ¬€(){ return test; } } { let test = 5; āœ¦ { let test = 6; print(test);} print(test); }
  • 12. Array Comprehension [i for ( let i = 0; i < 3; i++ )] āœ¦ // => [0, 1, 2] function range(begin, end) { āœ¦ for (let i = begin; i < end; ++i) { yield i; } } [i for each (i in range(0, 3))]
  • 13. Destructuring var [newA, newB] = [a, b]; āœ¦ var newA = a, newB = b; āœ¦ [a, b] = [b, a] āœ¦ function test(){ return [0, 1]; } āœ¦ let [a, b] = test(); var [, c] = test(); var {name: name} = {name: ā€œJohnā€} āœ¦ name == ā€œJohnā€ var {name} = {name: ā€œJohnā€} āœ¦
  • 14. JavaScript 1.8 Mostly a bug ļ¬x release āœ¦ Expression Closures āœ¦ function(x){ return x * x; } function(x) x * x; Generator Expressions āœ¦ function val_iter(obj) { return (obj[x] for (x in obj)); } for ( let value in val_iter(obj) ) { ... }
  • 15. reduce Great for summing or concating āœ¦ [x for ( x in 100 )] .reduce(function(a,b) a+b); [[...],[...]] āœ¦ .reduce(function(a,b){ a.concat(b);}, []) reduceRight āœ¦
  • 16. JavaScript 1.9 Merge object properties: āœ¦ Object.extend( baseObj, otherObj ) Function.prototype.bind() āœ¦ fn.bind(someThis) ā€œ string ā€.trim() āœ¦ // => ā€œstringā€ mozilla.hashcode(someObj) āœ¦ // => 1234 (unique ID)
  • 17. deļ¬neProperty Object.deļ¬neProperty(obj, name, value, āœ¦ types) var obj = {}; āœ¦ Object.deļ¬neProperty(obj, ā€œnameā€, ā€œJohnā€, Object.NOT_WRITABLE | Object.NOT_DELETABLE); obj.name = ā€œTestā€; obj.name == ā€œJohnā€; delete obj.name obj.name == ā€œJohnā€;
  • 18. JSON mozilla.JSON.parse(ā€œ{name:ā€™Johnā€™}ā€) āœ¦ // => {name: ā€˜Johnā€™} mozilla.JSON.serialize({name:ā€™Johnā€™}) āœ¦ // => ā€œ{name:ā€™Johnā€™}ā€
  • 19. Catchalls var props = {}; āœ¦ var obj = { test: true, get *(name){ return props[name]; }, set *(name, value){ props[name] = value; } } obj.__deļ¬neGetter_(ā€œā€, function(){}) āœ¦
  • 20. JavaScript 2 Goals Backwards Compatible āœ¦ Suitable to developing large systems āœ¦ Allow for reusable libraries āœ¦ Merge previous eļ¬€orts (ActionScript) āœ¦ Fix ECMAScript 3 bugs āœ¦ Keep it usable for small programs āœ¦
  • 21. Features Classes and Interfaces āœ¦ Packages and Namespaces āœ¦ Type Annotations āœ¦ Strict Veriļ¬cation āœ¦ Optimization āœ¦ Syntax Shortcuts āœ¦ Iterators and Generators āœ¦ Self-hosting āœ¦
  • 22. The Direction ECMAScript 4 JavaScript 2 ActionScript 4 JScript Etc. Screaming Tamarin KJS (Apple) Monkey Opera
  • 23. Tamarin Tamarin āœ¦ āœ¦ New Virtual Machine from Adobe āœ¦ Perfect for ActionScript āœ¦ (a mutant cousin of JavaScript 2) The Three Monkeys: āœ¦ āœ¦ ActionMonkey āœ¦ ScreamingMonkey āœ¦ IronMonkey
  • 24. Three Monkies ActionMonkey āœ¦ āœ¦ Integrating Tamarin into SpiderMonkey āœ¦ Powering Firefox 4 (?) + JavaScript 2 ScreamingMonkey āœ¦ āœ¦ Forcing Tamarin into Internet Explorer āœ¦ (Kicking and screaming?) IronMonkey āœ¦ āœ¦ Bringing Python + Ruby to Tamarin
  • 26. Classes class Programmer { āœ¦ var name; var city = ā€œBoston, MAā€; const interest = ā€œcomputersā€; function work() {} } var p = new Programmer; āœ¦ p.name = ā€œJohnā€; p.work(); p.work.apply( someotherp ); p.interest = ā€œscienceā€; // Error
  • 27. Dynamic Classes dynamic class Programmer { āœ¦ var name; var city = ā€œBoston, MAā€; const interest = ā€œcomputersā€; function work() {} } var p = new Programmer; āœ¦ p.lastName = ā€œResigā€; for ( var i in p ) alert( i ); // alert( ā€œResigā€ );
  • 28. Getters and Setters class Programmer { āœ¦ var _name; function get name(){ return _name; } function set name(value){ _name = value + ā€œ Resigā€; } } var p = new Programmer; āœ¦ p.name = ā€œJohnā€; alert( p.name ); // ā€œJohn Resigā€
  • 29. Catch-Alls dynamic class Programmer { āœ¦ meta function get(name) { ... } meta function set(name, value) { alert(ā€œSetting ā€œ + name + ā€œ to ā€œ + value); } } var p = new Programmer āœ¦ p.name = ā€œJohnā€; // alert(ā€œSetting name to Johnā€);
  • 30. Inheritance class Artist { āœ¦ function draw() { alert(ā€œDrawing!ā€); } } class Designer extends Artist { override function draw() { alert(ā€œDesigning!ā€); } } var d = new Designer āœ¦ d.draw(); // alert(ā€œDesigning!ā€);
  • 31. Inheritance (cont.) ā€˜ļ¬nalā€™ methods canā€™t be overriden āœ¦ class Artist { āœ¦ ļ¬nal function draw() {alert(ā€œDrawing!ā€);} } class Designer extends Artist { // ERROR: Canā€™t override draw! override function draw() { alert(ā€œDesigning!ā€); } }
  • 32. Inheritance (cont.) ā€˜ļ¬nalā€™ classes canā€™t be inherited from āœ¦ ļ¬nal class Artist { āœ¦ function draw() { alert(ā€œDrawing!ā€); } } // ERROR: Canā€™t inherit from Artist class Designer extends Artist { override function draw() { alert(ā€œDesigning!ā€); } }
  • 33. Metaclass Provide global functions and properties on āœ¦ a class object class Users { āœ¦ static function ļ¬nd( name ) { // ... } } Users.ļ¬nd( ā€œJohnā€ ); āœ¦
  • 34. Interfaces Verify that a class implements another āœ¦ class Artist { āœ¦ function draw(); } class Designer implements Artist { function draw() { alert(ā€œDesigning!ā€); } } if ( Designer is Artist ) āœ¦ alert(ā€œDesigners are Artists!ā€);
  • 35. Types
  • 36. Types Types are broken down into: āœ¦ āœ¦ string āœ¦ double (ECMAScript 3-style Number) āœ¦ boolean
  • 37. Type Annotations var name : string = ā€œJohnā€; āœ¦ let x : double = 5.3; āœ¦ function stuļ¬€( x: string, obj: Object ) : āœ¦ boolean {}
  • 38. Function Types Only return speciļ¬c types: āœ¦ function isValid() : boolean { } Only be used on certain objects types: āœ¦ function every( this: Array ) { for ( var i = 0; i < this.length; i++ ) alert( this[i] ); } every.call( [0,1,2] ); // alert(0); alert(1); alert(2); every.call({a: ā€œbā€}); // ERROR
  • 39. Rest Arguments function stuļ¬€( name, ...values ){ āœ¦ alert( values.length ); } stuļ¬€( ā€œJohnā€, 1, 2, 3, 4 ); āœ¦ // alert( 4 ); function stuļ¬€( name : string, ...values : [double] ) : void āœ¦ { alert( values.length ); } var array = [1,2,3,4]; āœ¦ stuļ¬€( ā€œJohnā€, ...array );
  • 40. Union and Any Types var test : (string, double) = ā€œtestā€; āœ¦ test = 3; test = {}; // ERROR These are equivalent: āœ¦ āœ¦ var test : * = ā€œtestā€; āœ¦ var test = ā€œtestā€;
  • 41. Type Deļ¬nitions type Point = { x: double, y: double }; āœ¦ var p : Point = { x: 3.0, y: 24.0 }; āœ¦
  • 42. Nullability Prevent variables from accepting null āœ¦ values var name : * = ā€œJohnā€; āœ¦ var name : string! = ā€œJohnā€; āœ¦ name = ā€œTedā€; name = null; // ERROR function test( name: string? ) { āœ¦ alert( name ); }
  • 43. Initialization class User { āœ¦ var name : string!; // Must be initialized function User( n ) : name = n { // ... } }
  • 44. ā€œlikeā€ type Point = { x: double, y: double }; āœ¦ if ( { x: 3, y: 5 } like Point ) āœ¦ alert( ā€œThat looks like a point to me!ā€ ); if ( !({ x: 3 } like Point) ) āœ¦ alert( ā€œNot a point!ā€ ); // Loop over array-like things: āœ¦ function every( a: like { length: double } ) { for ( var i = 0; i < a.length; i++ ) alert( a[i] ); }
  • 45. Parameterized Types var m: Map.<string, *>; āœ¦ class Point.<T> { āœ¦ var x: T, y: T; } var p = new Point.<double>; āœ¦ p.x = 3.0; p.y = 5.0;
  • 47. Namespaces namespace extra = ā€œextraā€; āœ¦ Pre-deļ¬ned namespaces: āœ¦ āœ¦ __ES4__ āœ¦ intrinsic āœ¦ iterator āœ¦ meta Namespaced variables: āœ¦ iteration::StopIteration intrinsic::readFile
  • 48. Multimethods generic function intersect(s1, s2); āœ¦ generic function intersect(s1: Shape, s2: Shape ) { // ... } generic function intersect(s1: Rect, s2: Rect ) { // ... } generic function test(a: Object?, b... āœ¦ generic function test(a: Object! āœ¦
  • 49. Iteration class Fib { āœ¦ private var a=0, b=1; iterator function get(deep:boolean = false) : IteratorType.<double> this public function next(): double { if ( b > 100 ) throw iterator::StopIteration; [a,b] = [b,a+b]; return a; } } for ( let i in new Fib ) āœ¦ alert( i );
  • 50. For .. Each For each loops through values āœ¦ let s = ā€œā€; āœ¦ for each ( let n in [ā€œaā€,ā€bā€,ā€cā€] ) s += n; alert(s); // ā€œabcā€
  • 52. Map.es The reference implementationā€™s classes are āœ¦ written in ECMAScript package āœ¦ { use namespace intrinsic; use default namespace public; intrinsic class Map.<K,V> { static const length = 2; function Map(equals=intrinsic::===, hashcode=intrinsic::hashcode) : equals = equals , hashcode = hashcode , element_count = 0 { } // ... }
  • 53. More Info ECMAScript 4 Progress: āœ¦ http://spreadsheets.google.com/ccc?key=pFIHldY_CkszsFxMkQOReAQ&hl=en ECMAScript 4 White Paper Overview: āœ¦ http://www.ecmascript.org/es4/spec/overview.pdf Blogging: āœ¦ http://ejohn.org/