SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

En vedette (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
 

Dernier

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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
 
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
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Dernier (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
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
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
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...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

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

Notes de l'éditeur

  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