SlideShare ist ein Scribd-Unternehmen logo
1 von 19
JavaScript
  for Rubyists
jQuery
but I already do JS?
“JavaScript is the only language that people
  think they can program without actually
         learning it.” - D.Crockford
refresher
backbone and node need it
basic grammar
familiar object model



 Ruby           JS
 object       object
familiar object model



 Ruby
               JS
 object      object
                         JS
                      primitive
JS datatypes
primitives           objects


• Boolean            • Object
• Number (fp)        • Array (object)
• String (16-bit)
• nil/undefined/NaN
Core syntax
Ruby                JavaScript


• no semicolons     • optional semicolons*
• # + =begin/=end   • // + /* */
• implicit return   • return required
• do/end or {}      • {}
the bad stuff
hey! It was made in 10 days
beware!
• Global variables      •+
• Scope                 • NaN
• Semicolon insertion   • Phony arrays
• Reserved words        • Falsy values
• typeof                • ==
• parseInt              • eval
the good stuff
  it’s actually very lispy
functions are objects

 Ruby                    JavaScript
1 def my_function arg1   1   function myFunction(arg1){
2   something arg1       2     something(arg1);
3 end                    3   }
4                        4
                         5   var myFunction = function(arg1){
                         6     something(arg1);
                         7   }
                         8
functions are objects

    Ruby                             JavaScript
1   def my_function arg1             1   function myFunction(arg1){
2     something arg1                 2     something(arg1);
3   end                              3   }
4                                    4
5   my_function = lambda do |arg1|   5   var myFunction = function(arg1){
6     something arg1                 6     something(arg1);
7   end                              7   }
8                                    8
object literals

Ruby                           JavaScript

1   # hashie gem + objects     1 // new object with var
2   require (‘hashie’)         2 var obj = {name: ‘simon’};
3
4   a = {:name => ‘simon’}
5   obj = Hashie::Mash.new a
6   obj.name #=> simon
dynamic objects

 Ruby                           JavaScript

 1   # hashie gem + objects     1   // new object with var
 2   require (‘hashie’)         2   var obj = {name: ‘simon’};
 3                              3
 4   a = {:name => ‘simon’}     4   // new object with function
 5   obj = Hashie::Mash.new a   5   obj.hello_world = function(){
 6   obj.name #=> simon         6     return “Hola Mundo”;
 7                              7   }
 8   def obj.hello_world
 9     puts "Hola Mundo"
10   end
want to try?
http://jsconsole.com
resources


•   http://www.youtube.com/watch?v=hQVTIJBZook

•   http://oreilly.com/catalog/9780596517748

•   http://javascript.crockford.com/survey.html
thanks!
 @tokumin

Weitere ähnliche Inhalte

Andere mochten auch (14)

Greater Tumen Region Cross Border Tourism Routes Summary
Greater Tumen Region Cross Border Tourism Routes SummaryGreater Tumen Region Cross Border Tourism Routes Summary
Greater Tumen Region Cross Border Tourism Routes Summary
 
Recurso apelacion1
Recurso apelacion1Recurso apelacion1
Recurso apelacion1
 
Root Canal Morphology
Root Canal MorphologyRoot Canal Morphology
Root Canal Morphology
 
Cinemática 1 d
Cinemática 1 dCinemática 1 d
Cinemática 1 d
 
Pengelolaan usaha ku
Pengelolaan usaha kuPengelolaan usaha ku
Pengelolaan usaha ku
 
Bahasamalaysiapowerpointkssr1
Bahasamalaysiapowerpointkssr1Bahasamalaysiapowerpointkssr1
Bahasamalaysiapowerpointkssr1
 
Grupo 2 fabricacion de azucar
Grupo 2 fabricacion de azucarGrupo 2 fabricacion de azucar
Grupo 2 fabricacion de azucar
 
Final report for oap butterfly garden
Final report for oap butterfly gardenFinal report for oap butterfly garden
Final report for oap butterfly garden
 
La campagne
La campagneLa campagne
La campagne
 
Agradecer
AgradecerAgradecer
Agradecer
 
MORNAY RESUME
MORNAY RESUMEMORNAY RESUME
MORNAY RESUME
 
Asselin Resume Dec 2015 Final
Asselin Resume Dec 2015 FinalAsselin Resume Dec 2015 Final
Asselin Resume Dec 2015 Final
 
Coastal and Small Island Tourism brochure
Coastal and Small Island Tourism brochureCoastal and Small Island Tourism brochure
Coastal and Small Island Tourism brochure
 
Smilde corporate short linked in
Smilde corporate short linked inSmilde corporate short linked in
Smilde corporate short linked in
 

Kürzlich hochgeladen

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Javascript for Rubyists

  • 1. JavaScript for Rubyists
  • 3. “JavaScript is the only language that people think they can program without actually learning it.” - D.Crockford
  • 6. familiar object model Ruby JS object object
  • 7. familiar object model Ruby JS object object JS primitive
  • 8. JS datatypes primitives objects • Boolean • Object • Number (fp) • Array (object) • String (16-bit) • nil/undefined/NaN
  • 9. Core syntax Ruby JavaScript • no semicolons • optional semicolons* • # + =begin/=end • // + /* */ • implicit return • return required • do/end or {} • {}
  • 10. the bad stuff hey! It was made in 10 days
  • 11. beware! • Global variables •+ • Scope • NaN • Semicolon insertion • Phony arrays • Reserved words • Falsy values • typeof • == • parseInt • eval
  • 12. the good stuff it’s actually very lispy
  • 13. functions are objects Ruby JavaScript 1 def my_function arg1 1 function myFunction(arg1){ 2 something arg1 2 something(arg1); 3 end 3 } 4 4 5 var myFunction = function(arg1){ 6 something(arg1); 7 } 8
  • 14. functions are objects Ruby JavaScript 1 def my_function arg1 1 function myFunction(arg1){ 2 something arg1 2 something(arg1); 3 end 3 } 4 4 5 my_function = lambda do |arg1| 5 var myFunction = function(arg1){ 6 something arg1 6 something(arg1); 7 end 7 } 8 8
  • 15. object literals Ruby JavaScript 1 # hashie gem + objects 1 // new object with var 2 require (‘hashie’) 2 var obj = {name: ‘simon’}; 3 4 a = {:name => ‘simon’} 5 obj = Hashie::Mash.new a 6 obj.name #=> simon
  • 16. dynamic objects Ruby JavaScript 1 # hashie gem + objects 1 // new object with var 2 require (‘hashie’) 2 var obj = {name: ‘simon’}; 3 3 4 a = {:name => ‘simon’} 4 // new object with function 5 obj = Hashie::Mash.new a 5 obj.hello_world = function(){ 6 obj.name #=> simon 6 return “Hola Mundo”; 7 7 } 8 def obj.hello_world 9 puts "Hola Mundo" 10 end
  • 18. resources • http://www.youtube.com/watch?v=hQVTIJBZook • http://oreilly.com/catalog/9780596517748 • http://javascript.crockford.com/survey.html

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. explained in more detail in the handout\n
  12. If there were to be a language entirely based on the idea of monkeypatching, this could be it.\n
  13. \n
  14. functions are like Ruby Lambdas\n
  15. or like OpenStruct in Ruby 1.9.x\n
  16. \n
  17. \n
  18. \n
  19. \n