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 Jasmine
Paulo Ragonha
 
Socket applications
Socket applicationsSocket applications
Socket applications
João Moura
 
Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011
Chris Alfano
 

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

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+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
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Recently uploaded (20)

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...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
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
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%+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...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%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 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
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
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...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%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
 

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