SlideShare a Scribd company logo
Paren-free
                              Brendan Eich
                          brendan@mozilla.org




Saturday, June 11, 2011
Motivation




Saturday, June 11, 2011
History




Saturday, June 11, 2011
History

                     •    JS derives from Java from C++ from C (via early C and B), from
                          BCPL. BCPL had paren-free if, etc., heads disambiguated via the
                          do reserved word to separate an expression consequent, avoiding
                          ambiguity.




Saturday, June 11, 2011
History

                     •    JS derives from Java from C++ from C (via early C and B), from
                          BCPL. BCPL had paren-free if, etc., heads disambiguated via the
                          do reserved word to separate an expression consequent, avoiding
                          ambiguity.

                     •    Many JS style guides favor mandatory bracing of if consequents
                          and other sub-statement bodies, in order to avoid dangling else bugs.




Saturday, June 11, 2011
History

                     •    JS derives from Java from C++ from C (via early C and B), from
                          BCPL. BCPL had paren-free if, etc., heads disambiguated via the
                          do reserved word to separate an expression consequent, avoiding
                          ambiguity.

                     •    Many JS style guides favor mandatory bracing of if consequents
                          and other sub-statement bodies, in order to avoid dangling else bugs.

                     •    By comparison to nearby programming languages, JS syntax is
                          “shifty” to write and noisy to read. Can we do better?




Saturday, June 11, 2011
Examples
                if year > 2010 {
                    syntax++
                }

                for let i of iter {                 // i is fresh on each iteration
                    frob(i)
                }

                while lo <= hi {
                    let mid = (lo + hi) / 2

                          // binary search body goes here
                }

                ... return [i * i for i in range(n)]        // array comprehension




Saturday, June 11, 2011
Examples, cont.
                     •    Must support:        •   but not mandate:

                           if x < y {               if x < y {


                           } else if x < z {        } else {

                           } else if x < w {            if x < z {

                           } else {                     } else {

                           }                                if x < w {

                                                            } else {

                                                            }
                                                        }
                                                    }




Saturday, June 11, 2011
Syntax
                     •    IfStatement :

                            if   Expression SubStatement else SubStatement
                            if   Expression SubStatement
                            if   ( Expression ) OtherStatement else Statement
                            if   ( Expression ) OtherStatement

                     •    etc. for while, do-while, for, switch, catch

                     •    SubStatement :

                            Block
                            KeywordStatement




Saturday, June 11, 2011
Syntax, cont.
                     •    KeywordStatement :    •   Statement :

                           IfStatement               Block
                           IterationStatement        KeywordStatement
                           ContinueStatement         OtherStatement
                           BreakStatement
                           ReturnStatement
                           SwitchStatement
                                                •   OtherStatement :

                           ThrowStatement
                           TryStatement              EmptyStatement
                           DebuggerStatement         ExpressionStatement
                                                     LabelledStatement
                                                     VariableStatement




Saturday, June 11, 2011
Compatibility




Saturday, June 11, 2011
Compatibility
                     •    if, while, do-while, and switch statements, where the
                          head syntax is Expression, which may be over-parenthesized.




Saturday, June 11, 2011
Compatibility
                     •    if, while, do-while, and switch statements, where the
                          head syntax is Expression, which may be over-parenthesized.

                     •    try, catch, finally must be braced as in ES3 and ES5.




Saturday, June 11, 2011
Compatibility
                     •    if, while, do-while, and switch statements, where the
                          head syntax is Expression, which may be over-parenthesized.

                     •    try, catch, finally must be braced as in ES3 and ES5.

                     •    catch heads may be parenthesized or unparenthesized.




Saturday, June 11, 2011
Compatibility
                     •    if, while, do-while, and switch statements, where the
                          head syntax is Expression, which may be over-parenthesized.

                     •    try, catch, finally must be braced as in ES3 and ES5.

                     •    catch heads may be parenthesized or unparenthesized.

                     •    for heads may be parenthesized or unparenthesized.




Saturday, June 11, 2011
Compatibility
                     •    if, while, do-while, and switch statements, where the
                          head syntax is Expression, which may be over-parenthesized.

                     •    try, catch, finally must be braced as in ES3 and ES5.

                     •    catch heads may be parenthesized or unparenthesized.

                     •    for heads may be parenthesized or unparenthesized.

                     •    for-in/of heads may be parenthesized or unparenthesized.




Saturday, June 11, 2011
Compatibility
                     •    if, while, do-while, and switch statements, where the
                          head syntax is Expression, which may be over-parenthesized.

                     •    try, catch, finally must be braced as in ES3 and ES5.

                     •    catch heads may be parenthesized or unparenthesized.

                     •    for heads may be parenthesized or unparenthesized.

                     •    for-in/of heads may be parenthesized or unparenthesized.

                     •    for-of loop, comprehension, and generator expression new
                          semantics (next slide).




Saturday, June 11, 2011
for-in & for-of




Saturday, June 11, 2011
for-in & for-of
                     •    for k in o iterates over keys not values for all objects o.




Saturday, June 11, 2011
for-in & for-of
                     •    for k in o iterates over keys not values for all objects o.

                     •    for k of {p:1, q:2} iterates over 1, 2.




Saturday, June 11, 2011
for-in & for-of
                     •    for k in o iterates over keys not values for all objects o.

                     •    for k of {p:1, q:2} iterates over 1, 2.

                     •    for v of [3, 4, 5] iterates over 3, 4, 5.




Saturday, June 11, 2011
for-in & for-of
                     •    for k in o iterates over keys not values for all objects o.

                     •    for k of {p:1, q:2} iterates over 1, 2.

                     •    for v of [3, 4, 5] iterates over 3, 4, 5.

                     •    for k of keys(o) iterates over keys in o.




Saturday, June 11, 2011
for-in & for-of
                     •    for k in o iterates over keys not values for all objects o.

                     •    for k of {p:1, q:2} iterates over 1, 2.

                     •    for v of [3, 4, 5] iterates over 3, 4, 5.

                     •    for k of keys(o) iterates over keys in o.

                     •    for v of values(o) iterates over values in o.




Saturday, June 11, 2011
for-in & for-of
                     •    for k in o iterates over keys not values for all objects o.

                     •    for k of {p:1, q:2} iterates over 1, 2.

                     •    for v of [3, 4, 5] iterates over 3, 4, 5.

                     •    for k of keys(o) iterates over keys in o.

                     •    for v of values(o) iterates over values in o.

                     •    for [k, v] of items(o) iterates over key/value pairs.




Saturday, June 11, 2011
for-in & for-of
                     •    for k in o iterates over keys not values for all objects o.

                     •    for k of {p:1, q:2} iterates over 1, 2.

                     •    for v of [3, 4, 5] iterates over 3, 4, 5.

                     •    for k of keys(o) iterates over keys in o.

                     •    for v of values(o) iterates over values in o.

                     •    for [k, v] of items(o) iterates over key/value pairs.

                     •    for x of proxy iterates using the handler iterate trap.
                          (http://wiki.ecmascript.org/doku.php?id=harmony:iterators)



Saturday, June 11, 2011

More Related Content

Viewers also liked

Capitol js
Capitol jsCapitol js
Capitol js
Brendan Eich
 
Mozilla's NodeConf talk
Mozilla's NodeConf talkMozilla's NodeConf talk
Mozilla's NodeConf talk
Brendan Eich
 
Mozilla Research Party Talk
Mozilla Research Party TalkMozilla Research Party Talk
Mozilla Research Party Talk
Brendan Eich
 
dotJS 2015
dotJS 2015dotJS 2015
dotJS 2015
Brendan Eich
 
Always bet on JS - Finjs.io NYC 2016
Always bet on JS - Finjs.io NYC 2016Always bet on JS - Finjs.io NYC 2016
Always bet on JS - Finjs.io NYC 2016
Brendan Eich
 
Extensible Operators and Literals for JavaScript
Extensible Operators and Literals for JavaScriptExtensible Operators and Literals for JavaScript
Extensible Operators and Literals for JavaScript
Brendan Eich
 
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Brendan Eich
 
Value objects in JS - an ES7 work in progress
Value objects in JS - an ES7 work in progressValue objects in JS - an ES7 work in progress
Value objects in JS - an ES7 work in progress
Brendan Eich
 
Splash
SplashSplash
Splash
Brendan Eich
 
Txjs talk
Txjs talkTxjs talk
Txjs talk
Brendan Eich
 
The Same-Origin Saga
The Same-Origin SagaThe Same-Origin Saga
The Same-Origin Saga
Brendan Eich
 
Int64
Int64Int64

Viewers also liked (13)

Capitol js
Capitol jsCapitol js
Capitol js
 
Mozilla's NodeConf talk
Mozilla's NodeConf talkMozilla's NodeConf talk
Mozilla's NodeConf talk
 
Taysom seminar
Taysom seminarTaysom seminar
Taysom seminar
 
Mozilla Research Party Talk
Mozilla Research Party TalkMozilla Research Party Talk
Mozilla Research Party Talk
 
dotJS 2015
dotJS 2015dotJS 2015
dotJS 2015
 
Always bet on JS - Finjs.io NYC 2016
Always bet on JS - Finjs.io NYC 2016Always bet on JS - Finjs.io NYC 2016
Always bet on JS - Finjs.io NYC 2016
 
Extensible Operators and Literals for JavaScript
Extensible Operators and Literals for JavaScriptExtensible Operators and Literals for JavaScript
Extensible Operators and Literals for JavaScript
 
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
 
Value objects in JS - an ES7 work in progress
Value objects in JS - an ES7 work in progressValue objects in JS - an ES7 work in progress
Value objects in JS - an ES7 work in progress
 
Splash
SplashSplash
Splash
 
Txjs talk
Txjs talkTxjs talk
Txjs talk
 
The Same-Origin Saga
The Same-Origin SagaThe Same-Origin Saga
The Same-Origin Saga
 
Int64
Int64Int64
Int64
 

Recently uploaded

Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 

Recently uploaded (20)

Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 

Paren free

  • 1. Paren-free Brendan Eich brendan@mozilla.org Saturday, June 11, 2011
  • 4. History • JS derives from Java from C++ from C (via early C and B), from BCPL. BCPL had paren-free if, etc., heads disambiguated via the do reserved word to separate an expression consequent, avoiding ambiguity. Saturday, June 11, 2011
  • 5. History • JS derives from Java from C++ from C (via early C and B), from BCPL. BCPL had paren-free if, etc., heads disambiguated via the do reserved word to separate an expression consequent, avoiding ambiguity. • Many JS style guides favor mandatory bracing of if consequents and other sub-statement bodies, in order to avoid dangling else bugs. Saturday, June 11, 2011
  • 6. History • JS derives from Java from C++ from C (via early C and B), from BCPL. BCPL had paren-free if, etc., heads disambiguated via the do reserved word to separate an expression consequent, avoiding ambiguity. • Many JS style guides favor mandatory bracing of if consequents and other sub-statement bodies, in order to avoid dangling else bugs. • By comparison to nearby programming languages, JS syntax is “shifty” to write and noisy to read. Can we do better? Saturday, June 11, 2011
  • 7. Examples if year > 2010 { syntax++ } for let i of iter { // i is fresh on each iteration frob(i) } while lo <= hi { let mid = (lo + hi) / 2 // binary search body goes here } ... return [i * i for i in range(n)] // array comprehension Saturday, June 11, 2011
  • 8. Examples, cont. • Must support: • but not mandate: if x < y { if x < y { } else if x < z { } else { } else if x < w { if x < z { } else { } else { } if x < w { } else { } } } Saturday, June 11, 2011
  • 9. Syntax • IfStatement : if Expression SubStatement else SubStatement if Expression SubStatement if ( Expression ) OtherStatement else Statement if ( Expression ) OtherStatement • etc. for while, do-while, for, switch, catch • SubStatement : Block KeywordStatement Saturday, June 11, 2011
  • 10. Syntax, cont. • KeywordStatement : • Statement : IfStatement Block IterationStatement KeywordStatement ContinueStatement OtherStatement BreakStatement ReturnStatement SwitchStatement • OtherStatement : ThrowStatement TryStatement EmptyStatement DebuggerStatement ExpressionStatement LabelledStatement VariableStatement Saturday, June 11, 2011
  • 12. Compatibility • if, while, do-while, and switch statements, where the head syntax is Expression, which may be over-parenthesized. Saturday, June 11, 2011
  • 13. Compatibility • if, while, do-while, and switch statements, where the head syntax is Expression, which may be over-parenthesized. • try, catch, finally must be braced as in ES3 and ES5. Saturday, June 11, 2011
  • 14. Compatibility • if, while, do-while, and switch statements, where the head syntax is Expression, which may be over-parenthesized. • try, catch, finally must be braced as in ES3 and ES5. • catch heads may be parenthesized or unparenthesized. Saturday, June 11, 2011
  • 15. Compatibility • if, while, do-while, and switch statements, where the head syntax is Expression, which may be over-parenthesized. • try, catch, finally must be braced as in ES3 and ES5. • catch heads may be parenthesized or unparenthesized. • for heads may be parenthesized or unparenthesized. Saturday, June 11, 2011
  • 16. Compatibility • if, while, do-while, and switch statements, where the head syntax is Expression, which may be over-parenthesized. • try, catch, finally must be braced as in ES3 and ES5. • catch heads may be parenthesized or unparenthesized. • for heads may be parenthesized or unparenthesized. • for-in/of heads may be parenthesized or unparenthesized. Saturday, June 11, 2011
  • 17. Compatibility • if, while, do-while, and switch statements, where the head syntax is Expression, which may be over-parenthesized. • try, catch, finally must be braced as in ES3 and ES5. • catch heads may be parenthesized or unparenthesized. • for heads may be parenthesized or unparenthesized. • for-in/of heads may be parenthesized or unparenthesized. • for-of loop, comprehension, and generator expression new semantics (next slide). Saturday, June 11, 2011
  • 18. for-in & for-of Saturday, June 11, 2011
  • 19. for-in & for-of • for k in o iterates over keys not values for all objects o. Saturday, June 11, 2011
  • 20. for-in & for-of • for k in o iterates over keys not values for all objects o. • for k of {p:1, q:2} iterates over 1, 2. Saturday, June 11, 2011
  • 21. for-in & for-of • for k in o iterates over keys not values for all objects o. • for k of {p:1, q:2} iterates over 1, 2. • for v of [3, 4, 5] iterates over 3, 4, 5. Saturday, June 11, 2011
  • 22. for-in & for-of • for k in o iterates over keys not values for all objects o. • for k of {p:1, q:2} iterates over 1, 2. • for v of [3, 4, 5] iterates over 3, 4, 5. • for k of keys(o) iterates over keys in o. Saturday, June 11, 2011
  • 23. for-in & for-of • for k in o iterates over keys not values for all objects o. • for k of {p:1, q:2} iterates over 1, 2. • for v of [3, 4, 5] iterates over 3, 4, 5. • for k of keys(o) iterates over keys in o. • for v of values(o) iterates over values in o. Saturday, June 11, 2011
  • 24. for-in & for-of • for k in o iterates over keys not values for all objects o. • for k of {p:1, q:2} iterates over 1, 2. • for v of [3, 4, 5] iterates over 3, 4, 5. • for k of keys(o) iterates over keys in o. • for v of values(o) iterates over values in o. • for [k, v] of items(o) iterates over key/value pairs. Saturday, June 11, 2011
  • 25. for-in & for-of • for k in o iterates over keys not values for all objects o. • for k of {p:1, q:2} iterates over 1, 2. • for v of [3, 4, 5] iterates over 3, 4, 5. • for k of keys(o) iterates over keys in o. • for v of values(o) iterates over values in o. • for [k, v] of items(o) iterates over key/value pairs. • for x of proxy iterates using the handler iterate trap. (http://wiki.ecmascript.org/doku.php?id=harmony:iterators) Saturday, June 11, 2011