SlideShare a Scribd company logo
1 of 27
Download to read offline
Good/Bad Parts 
Syntactic Sugar 
Classes 
CoeeScript 
Vladimir Dobriakov, www.mobile-web-consulting.de 
FrankfurtJS, 30th of October 2014 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
JavaScript, 
the good parts 
+ 
syntactic sugar 
= 
CoeeScript 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Lexical Scoping, Globals 
for own 
switch 
Existential Operator 
Lexical Scoping, Globals 
items = $(li); 
$(#totals).text(items.length +  items found); 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Lexical Scoping, Globals 
for own 
switch 
Existential Operator 
Lexical Scoping, Globals 
var items; 
items = $(li); 
$(#totals).text(items.length +  items found); 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Lexical Scoping, Globals 
for own 
switch 
Existential Operator 
Lexical Scoping, Globals 
(function() { 
var items; 
items = $(li); 
$(#totals).text(items.length +  items found); 
}).call(this); 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Lexical Scoping, Globals 
for own 
switch 
Existential Operator 
Lexical Scoping, Globals 
(function() { 
var items; 
items = $(li); 
$(#totals).text(items.length +  items found); 
}).call(this); 
CoeeScript: 
items = $(li) 
$(totals).text(items.length +  items found) 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Lexical Scoping, Globals 
for own 
switch 
Existential Operator 
Iterate through Properties 
for (propertyName in customer) { 
value = customer[propertyName]; 
alert(propertName, value); 
} 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Lexical Scoping, Globals 
for own 
switch 
Existential Operator 
Iterate through Properties 
var propertyName, value, 
__hasProp = {}.hasOwnProperty; 
for (propertyName in customer) { 
if (!__hasProp.call(customer, propertyName)) continue; 
value = customer[propertyName]; 
alert(propertName, value); 
} 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Lexical Scoping, Globals 
for own 
switch 
Existential Operator 
Iterate through Properties 
var propertyName, value, 
__hasProp = {}.hasOwnProperty; 
for (propertyName in customer) { 
if (!__hasProp.call(customer, propertyName)) continue; 
value = customer[propertyName]; 
alert(propertName, value); 
} 
for own propertyName, value of customer # CoffeeScript 
alert(propertName, value) 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Lexical Scoping, Globals 
for own 
switch 
Existential Operator 
switch 
switch (day) { // JavaScript 
case Mon: 
go(work); 
case Tue: 
go(iceFishing); 
default: 
chill(24); 
} 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Lexical Scoping, Globals 
for own 
switch 
Existential Operator 
switch 
switch (day) { // JavaScript 
case Mon: 
go(work); break; 
case Tue: 
go(iceFishing); break; 
default: 
chill(24); 
} 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Lexical Scoping, Globals 
for own 
switch 
Existential Operator 
switch 
switch (day) { // JavaScript 
case Mon: 
go(work); break; 
case Tue: 
go(iceFishing); break; 
default: 
chill(24); 
} 
switch day # CoffeeScript 
when Mon then go work 
when Tue then go iceFishing 
else chill 24 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Lexical Scoping, Globals 
for own 
switch 
Existential Operator 
Check for Optional Parameter 
if (defaultAmount) 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Lexical Scoping, Globals 
for own 
switch 
Existential Operator 
Check for Optional Parameter 
if (defaultAmount) 
if (defaultAmount != null) 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Lexical Scoping, Globals 
for own 
switch 
Existential Operator 
Check for Optional Parameter 
if (defaultAmount) 
if (defaultAmount != null) 
if (typeof defaultAmount !== 'undefined'  
defaultAmount != null) 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Lexical Scoping, Globals 
for own 
switch 
Existential Operator 
Check for Optional Parameter 
if (defaultAmount) 
if (defaultAmount != null) 
if (typeof defaultAmount !== 'undefined'  
defaultAmount != null) 
CoeeScript: 
if defaultAmount? 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Lexical Scoping, Globals 
for own 
switch 
Existential Operator 
[optional] comparision 
0 ==  
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Lexical Scoping, Globals 
for own 
switch 
Existential Operator 
[optional] comparision 
0 ==  
Use === instead 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
List Comprehensions 
Splats, Destructuring Assignment 
String Interpolation 
List Comprehensions 
shortNames = (name for name in list when name.length  5) 
cubes = (math.cube num for num in list) 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
List Comprehensions 
Splats, Destructuring Assignment 
String Interpolation 
Splats, Destructuring Assignment 
awardMedals = (first, second, others...) - 
# TODO implementation 
awardMedals 'CoffeeScript', 'JavaScript', 'Ruby', 'Python' 
[city, temp, forecast] = weatherReport Frankfurt 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
List Comprehensions 
Splats, Destructuring Assignment 
String Interpolation 
in/of 
winner = yes if pick in 
[47, 92, 13] 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
List Comprehensions 
Splats, Destructuring Assignment 
String Interpolation 
String Interpolation 
Hello, #{name} 
html =  
strong 
Cup of CoffeeScript 
/strong 
 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Dene Classes 
Initializer 
Fat Arrow 
Access Prototype 
Dene Classes 
class Animal 
constructor: (name) - 
@name = name 
move: (meters) - 
alert #{@name} moved #{meters}m. 
class Snake extends Animal 
move: - 
alert Slithering... 
super 5 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Dene Classes 
Initializer 
Fat Arrow 
Access Prototype 
Initializer 
class Animal 
constructor: (@name) - 
(function() { 
var Animal; 
Animal = (function() { 
function Animal(name) { 
this.name = name; 
} 
return Animal; 
})(); 
).call(this); 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Dene Classes 
Initializer 
Fat Arrow 
Access Prototype 
Fat Arrow replaces this+that 
Account = (@customer, @cart) - 
$('.shopping_cart').bind 'click', 
(event) = 
@customer.purchase @cart 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Dene Classes 
Initializer 
Fat Arrow 
Access Prototype 
Access Prototype 
String::dasherize = - 
this.replace /_/g, - 
String.prototype.dasherize = function() { 
return this.replace(/_/g, -); 
}; 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
Good/Bad Parts 
Syntactic Sugar 
Classes 
Dene Classes 
Initializer 
Fat Arrow 
Access Prototype 
References 
Douglas Crockford JavaScript: The Good Parts 
http://coeescript.org/ 
Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript

More Related Content

Similar to JavaScript, the good parts + syntactic sugar = CoffeeScript

Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasminePaulo Ragonha
 
Isomorphic App Development with Ruby and Volt - Rubyconf2014
Isomorphic App Development with Ruby and Volt - Rubyconf2014Isomorphic App Development with Ruby and Volt - Rubyconf2014
Isomorphic App Development with Ruby and Volt - Rubyconf2014ryanstout
 
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey BuzdinMarvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey BuzdinJava User Group Latvia
 
Socket applications
Socket applicationsSocket applications
Socket applicationsJoão Moura
 
Good karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with KarmaGood karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with KarmaExoLeaders.com
 
Developer Best Practices - The secret sauce for coding modern software
Developer Best Practices - The secret sauce for coding modern softwareDeveloper Best Practices - The secret sauce for coding modern software
Developer Best Practices - The secret sauce for coding modern softwareKosala Nuwan Perera
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015jbandi
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Chris Alfano
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescriptDavid Furber
 
DIWE - Programming with JavaScript
DIWE - Programming with JavaScriptDIWE - Programming with JavaScript
DIWE - Programming with JavaScriptRasan Samarasinghe
 
Kakunin E2E framework showcase
Kakunin E2E framework showcaseKakunin E2E framework showcase
Kakunin E2E framework showcaseThe Software House
 
WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)Igor Khotin
 
greach 2014 marco vermeulen bdd using cucumber jvm and groovy
greach 2014 marco vermeulen bdd using cucumber jvm and groovygreach 2014 marco vermeulen bdd using cucumber jvm and groovy
greach 2014 marco vermeulen bdd using cucumber jvm and groovyJessie Evangelista
 
Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009Fabio Akita
 
Spring into rails
Spring into railsSpring into rails
Spring into railsHiro Asari
 

Similar to JavaScript, the good parts + syntactic sugar = CoffeeScript (20)

Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
Isomorphic App Development with Ruby and Volt - Rubyconf2014
Isomorphic App Development with Ruby and Volt - Rubyconf2014Isomorphic App Development with Ruby and Volt - Rubyconf2014
Isomorphic App Development with Ruby and Volt - Rubyconf2014
 
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey BuzdinMarvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
 
Introduction to Jooq
Introduction to JooqIntroduction to Jooq
Introduction to Jooq
 
Socket applications
Socket applicationsSocket applications
Socket applications
 
Good karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with KarmaGood karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with Karma
 
Volt 2015
Volt 2015Volt 2015
Volt 2015
 
Developer Best Practices - The secret sauce for coding modern software
Developer Best Practices - The secret sauce for coding modern softwareDeveloper Best Practices - The secret sauce for coding modern software
Developer Best Practices - The secret sauce for coding modern software
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
 
DIWE - Programming with JavaScript
DIWE - Programming with JavaScriptDIWE - Programming with JavaScript
DIWE - Programming with JavaScript
 
Kakunin E2E framework showcase
Kakunin E2E framework showcaseKakunin E2E framework showcase
Kakunin E2E framework showcase
 
WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)
 
greach 2014 marco vermeulen bdd using cucumber jvm and groovy
greach 2014 marco vermeulen bdd using cucumber jvm and groovygreach 2014 marco vermeulen bdd using cucumber jvm and groovy
greach 2014 marco vermeulen bdd using cucumber jvm and groovy
 
Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009
 
Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
 
Nodejs meetup-12-2-2015
Nodejs meetup-12-2-2015Nodejs meetup-12-2-2015
Nodejs meetup-12-2-2015
 
Spring into rails
Spring into railsSpring into rails
Spring into rails
 

Recently uploaded

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 

Recently uploaded (20)

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 

JavaScript, the good parts + syntactic sugar = CoffeeScript

  • 1. Good/Bad Parts Syntactic Sugar Classes CoeeScript Vladimir Dobriakov, www.mobile-web-consulting.de FrankfurtJS, 30th of October 2014 Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 2. Good/Bad Parts Syntactic Sugar Classes JavaScript, the good parts + syntactic sugar = CoeeScript Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 3. Good/Bad Parts Syntactic Sugar Classes Lexical Scoping, Globals for own switch Existential Operator Lexical Scoping, Globals items = $(li); $(#totals).text(items.length + items found); Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 4. Good/Bad Parts Syntactic Sugar Classes Lexical Scoping, Globals for own switch Existential Operator Lexical Scoping, Globals var items; items = $(li); $(#totals).text(items.length + items found); Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 5. Good/Bad Parts Syntactic Sugar Classes Lexical Scoping, Globals for own switch Existential Operator Lexical Scoping, Globals (function() { var items; items = $(li); $(#totals).text(items.length + items found); }).call(this); Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 6. Good/Bad Parts Syntactic Sugar Classes Lexical Scoping, Globals for own switch Existential Operator Lexical Scoping, Globals (function() { var items; items = $(li); $(#totals).text(items.length + items found); }).call(this); CoeeScript: items = $(li) $(totals).text(items.length + items found) Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 7. Good/Bad Parts Syntactic Sugar Classes Lexical Scoping, Globals for own switch Existential Operator Iterate through Properties for (propertyName in customer) { value = customer[propertyName]; alert(propertName, value); } Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 8. Good/Bad Parts Syntactic Sugar Classes Lexical Scoping, Globals for own switch Existential Operator Iterate through Properties var propertyName, value, __hasProp = {}.hasOwnProperty; for (propertyName in customer) { if (!__hasProp.call(customer, propertyName)) continue; value = customer[propertyName]; alert(propertName, value); } Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 9. Good/Bad Parts Syntactic Sugar Classes Lexical Scoping, Globals for own switch Existential Operator Iterate through Properties var propertyName, value, __hasProp = {}.hasOwnProperty; for (propertyName in customer) { if (!__hasProp.call(customer, propertyName)) continue; value = customer[propertyName]; alert(propertName, value); } for own propertyName, value of customer # CoffeeScript alert(propertName, value) Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 10. Good/Bad Parts Syntactic Sugar Classes Lexical Scoping, Globals for own switch Existential Operator switch switch (day) { // JavaScript case Mon: go(work); case Tue: go(iceFishing); default: chill(24); } Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 11. Good/Bad Parts Syntactic Sugar Classes Lexical Scoping, Globals for own switch Existential Operator switch switch (day) { // JavaScript case Mon: go(work); break; case Tue: go(iceFishing); break; default: chill(24); } Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 12. Good/Bad Parts Syntactic Sugar Classes Lexical Scoping, Globals for own switch Existential Operator switch switch (day) { // JavaScript case Mon: go(work); break; case Tue: go(iceFishing); break; default: chill(24); } switch day # CoffeeScript when Mon then go work when Tue then go iceFishing else chill 24 Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 13. Good/Bad Parts Syntactic Sugar Classes Lexical Scoping, Globals for own switch Existential Operator Check for Optional Parameter if (defaultAmount) Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 14. Good/Bad Parts Syntactic Sugar Classes Lexical Scoping, Globals for own switch Existential Operator Check for Optional Parameter if (defaultAmount) if (defaultAmount != null) Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 15. Good/Bad Parts Syntactic Sugar Classes Lexical Scoping, Globals for own switch Existential Operator Check for Optional Parameter if (defaultAmount) if (defaultAmount != null) if (typeof defaultAmount !== 'undefined' defaultAmount != null) Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 16. Good/Bad Parts Syntactic Sugar Classes Lexical Scoping, Globals for own switch Existential Operator Check for Optional Parameter if (defaultAmount) if (defaultAmount != null) if (typeof defaultAmount !== 'undefined' defaultAmount != null) CoeeScript: if defaultAmount? Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 17. Good/Bad Parts Syntactic Sugar Classes Lexical Scoping, Globals for own switch Existential Operator [optional] comparision 0 == Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 18. Good/Bad Parts Syntactic Sugar Classes Lexical Scoping, Globals for own switch Existential Operator [optional] comparision 0 == Use === instead Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 19. Good/Bad Parts Syntactic Sugar Classes List Comprehensions Splats, Destructuring Assignment String Interpolation List Comprehensions shortNames = (name for name in list when name.length 5) cubes = (math.cube num for num in list) Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 20. Good/Bad Parts Syntactic Sugar Classes List Comprehensions Splats, Destructuring Assignment String Interpolation Splats, Destructuring Assignment awardMedals = (first, second, others...) - # TODO implementation awardMedals 'CoffeeScript', 'JavaScript', 'Ruby', 'Python' [city, temp, forecast] = weatherReport Frankfurt Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 21. Good/Bad Parts Syntactic Sugar Classes List Comprehensions Splats, Destructuring Assignment String Interpolation in/of winner = yes if pick in [47, 92, 13] Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 22. Good/Bad Parts Syntactic Sugar Classes List Comprehensions Splats, Destructuring Assignment String Interpolation String Interpolation Hello, #{name} html = strong Cup of CoffeeScript /strong Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 23. Good/Bad Parts Syntactic Sugar Classes Dene Classes Initializer Fat Arrow Access Prototype Dene Classes class Animal constructor: (name) - @name = name move: (meters) - alert #{@name} moved #{meters}m. class Snake extends Animal move: - alert Slithering... super 5 Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 24. Good/Bad Parts Syntactic Sugar Classes Dene Classes Initializer Fat Arrow Access Prototype Initializer class Animal constructor: (@name) - (function() { var Animal; Animal = (function() { function Animal(name) { this.name = name; } return Animal; })(); ).call(this); Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 25. Good/Bad Parts Syntactic Sugar Classes Dene Classes Initializer Fat Arrow Access Prototype Fat Arrow replaces this+that Account = (@customer, @cart) - $('.shopping_cart').bind 'click', (event) = @customer.purchase @cart Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 26. Good/Bad Parts Syntactic Sugar Classes Dene Classes Initializer Fat Arrow Access Prototype Access Prototype String::dasherize = - this.replace /_/g, - String.prototype.dasherize = function() { return this.replace(/_/g, -); }; Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript
  • 27. Good/Bad Parts Syntactic Sugar Classes Dene Classes Initializer Fat Arrow Access Prototype References Douglas Crockford JavaScript: The Good Parts http://coeescript.org/ Vladimir Dobriakov, www.mobile-web-consulting.de CoeeScript