SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

Destacado

Cinemática 1 d
Cinemática 1 dCinemática 1 d
Cinemática 1 d
lorena025
 
Bahasamalaysiapowerpointkssr1
Bahasamalaysiapowerpointkssr1Bahasamalaysiapowerpointkssr1
Bahasamalaysiapowerpointkssr1
happyupsi
 
Final report for oap butterfly garden
Final report for oap butterfly gardenFinal report for oap butterfly garden
Final report for oap butterfly garden
miaomiaopig
 
Asselin Resume Dec 2015 Final
Asselin Resume Dec 2015 FinalAsselin Resume Dec 2015 Final
Asselin Resume Dec 2015 Final
Rob Asselin, MPM
 
Smilde corporate short linked in
Smilde corporate short linked inSmilde corporate short linked in
Smilde corporate short linked in
Debra Aurich
 

Destacado (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
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.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
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

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

Notas del editor

  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