SlideShare une entreprise Scribd logo
1  sur  19
Télécharger pour lire hors ligne
Javascript - Avoiding the
                        bad parts

                                   Mikko Ohtamaa
                             mikko@opensourcehacker.com

                              http://opensourcehacker.com


                              http://twitter.com/moo9000

Saturday, November 5, 2011
Lighting talk of 5 min
                             Turn Python gurus to JS gurus

                                Plone Conference 2011




Saturday, November 5, 2011
Javascript has become
                              better
                             Don’t write Javascript like it was 1996




Saturday, November 5, 2011
What your every JS file
                    should look like


Saturday, November 5, 2011
/*global require,define,window,console*/
                   // Main
                   require(["jquery", "domready!",
                   "submodule"], function($, domready,
                   submodule) {
                       "use strict";

                             $("a").click(function() {
                                 var val = submodule.foobar();
                                 window.alert(val);
                             });
                   });




Saturday, November 5, 2011
/*global require,define,window,console*/
   // Submodule
   define(["jquery", "myothermodule"], function($, myothermodule) {
       'use strict';

             // Export public module API
             return {
                 foobar : function() {
                      return 1+1+myothermodule.func();
                 }
             };
   });




Saturday, November 5, 2011
Use require.js
                    • AMD (Asynchronous Module Definition)
                    • a.k.a. import for Javascript
                    • Dependency solving
                    • Automatic compression and merging of
                             needed and only needed JS files using
                             require.js optimizer


Saturday, November 5, 2011
Use ECMAScript5

                    • Goodies: this.function.bind(),
                             Array.forEach()
                    • Backwards compatibility (Internet
                             Explorer): http://bit.ly/es5shim



Saturday, November 5, 2011
“use strict”;
                   Enforces no global variables by default and fixes some
                               other bad language features




Saturday, November 5, 2011
Enforce background
                    JSLint checking in your
                          text editor
                             ... or JSLint modern fork, JSHint




Saturday, November 5, 2011
Saturday, November 5, 2011
// Some JSLint hinting

                /*global window,console*/
Saturday, November 5, 2011
Never use Javascript
                               inline in HTML


Saturday, November 5, 2011
<a href=”#”
                             onclick=”aargh()”>
                                     No




Saturday, November 5, 2011
// On page load
     $("a#handler").click(function() {
         // do stuff
     });

     // For dynamic content
     // (AJAX loaded)
     $("#handler").live(function() {
         // do stuff
     });
Saturday, November 5, 2011
Passing a bound
                             method to an event
                                handler using
                               function.bind()

Saturday, November 5, 2011
function FooClass(){
  }
  FooClass.prototype.myfunc = function(arg1,arg2) {
  }
  var f = new Foo();

  // Bind arguments are this, arg1, arg2
  setTimeout(f.myfunc.bind(f, "arg1", "arg2"), 10);




Saturday, November 5, 2011
Finding Javascript info

                    • Use Mozilla Developer Network: “MDN
                             Javascript bind”
                    • Put w3school.com on ban-list - only bad
                             information there




Saturday, November 5, 2011
Conclusion
                    • Worst JS farts have been fixed / can be
                             worked around with discipline
                    • Javascript still lacks syntatic sugar, is not
                             wrist friendly (boo!)
                    • Mozilla et. al. are working on to fix that
                             (but Philip didn’t promise do drop curly
                             brackets or semicolons)


Saturday, November 5, 2011

Contenu connexe

Similaire à Avoid bad Javascript with RequireJS, ECMAScript5 and strict mode

Conquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JSConquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JSCaridy Patino
 
잘 알려지지 않은 Php 코드 활용하기
잘 알려지지 않은 Php 코드 활용하기잘 알려지지 않은 Php 코드 활용하기
잘 알려지지 않은 Php 코드 활용하기형우 안
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPsmueller_sandsmedia
 
3D in the Browser via WebGL: It's Go Time
3D in the Browser via WebGL: It's Go Time 3D in the Browser via WebGL: It's Go Time
3D in the Browser via WebGL: It's Go Time Pascal Rettig
 
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyTorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyBruno Oliveira
 
Social design (Seattle 09-2011)
Social design (Seattle 09-2011)Social design (Seattle 09-2011)
Social design (Seattle 09-2011)Andrei Zyuzikov
 
Writing jQuery that doesn't suck - London jQuery
Writing jQuery that doesn't suck - London jQueryWriting jQuery that doesn't suck - London jQuery
Writing jQuery that doesn't suck - London jQueryRoss Bruniges
 
The Solar Framework for PHP
The Solar Framework for PHPThe Solar Framework for PHP
The Solar Framework for PHPConFoo
 
Moving to Dojo 1.7 and the path to 2.0
Moving to Dojo 1.7 and the path to 2.0Moving to Dojo 1.7 and the path to 2.0
Moving to Dojo 1.7 and the path to 2.0James Thomas
 
Javascript Performance
Javascript PerformanceJavascript Performance
Javascript Performanceolivvv
 
Javascript Basics - part 1
Javascript Basics - part 1Javascript Basics - part 1
Javascript Basics - part 1Kasia Drzyzga
 
WebGL Fundamentals
WebGL FundamentalsWebGL Fundamentals
WebGL FundamentalsSencha
 
Web Scraping using Diazo!
Web Scraping using Diazo!Web Scraping using Diazo!
Web Scraping using Diazo!pythonchile
 
Puppet camp europe 2011 hackability
Puppet camp europe 2011   hackabilityPuppet camp europe 2011   hackability
Puppet camp europe 2011 hackabilityPuppet
 
Symony2 A Next Generation PHP Framework
Symony2 A Next Generation PHP FrameworkSymony2 A Next Generation PHP Framework
Symony2 A Next Generation PHP FrameworkRyan Weaver
 
Pluggable Django Application Patterns PyCon 2011
Pluggable Django Application Patterns PyCon 2011Pluggable Django Application Patterns PyCon 2011
Pluggable Django Application Patterns PyCon 2011Corey Oordt
 
The Fast, The Slow and the Lazy
The Fast, The Slow and the LazyThe Fast, The Slow and the Lazy
The Fast, The Slow and the LazyMaurício Linhares
 

Similaire à Avoid bad Javascript with RequireJS, ECMAScript5 and strict mode (20)

Caridy patino - node-js
Caridy patino - node-jsCaridy patino - node-js
Caridy patino - node-js
 
Conquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JSConquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JS
 
잘 알려지지 않은 Php 코드 활용하기
잘 알려지지 않은 Php 코드 활용하기잘 알려지지 않은 Php 코드 활용하기
잘 알려지지 않은 Php 코드 활용하기
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHP
 
Pocket Knife JS
Pocket Knife JSPocket Knife JS
Pocket Knife JS
 
Splash
SplashSplash
Splash
 
3D in the Browser via WebGL: It's Go Time
3D in the Browser via WebGL: It's Go Time 3D in the Browser via WebGL: It's Go Time
3D in the Browser via WebGL: It's Go Time
 
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyTorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
 
Social design (Seattle 09-2011)
Social design (Seattle 09-2011)Social design (Seattle 09-2011)
Social design (Seattle 09-2011)
 
Writing jQuery that doesn't suck - London jQuery
Writing jQuery that doesn't suck - London jQueryWriting jQuery that doesn't suck - London jQuery
Writing jQuery that doesn't suck - London jQuery
 
The Solar Framework for PHP
The Solar Framework for PHPThe Solar Framework for PHP
The Solar Framework for PHP
 
Moving to Dojo 1.7 and the path to 2.0
Moving to Dojo 1.7 and the path to 2.0Moving to Dojo 1.7 and the path to 2.0
Moving to Dojo 1.7 and the path to 2.0
 
Javascript Performance
Javascript PerformanceJavascript Performance
Javascript Performance
 
Javascript Basics - part 1
Javascript Basics - part 1Javascript Basics - part 1
Javascript Basics - part 1
 
WebGL Fundamentals
WebGL FundamentalsWebGL Fundamentals
WebGL Fundamentals
 
Web Scraping using Diazo!
Web Scraping using Diazo!Web Scraping using Diazo!
Web Scraping using Diazo!
 
Puppet camp europe 2011 hackability
Puppet camp europe 2011   hackabilityPuppet camp europe 2011   hackability
Puppet camp europe 2011 hackability
 
Symony2 A Next Generation PHP Framework
Symony2 A Next Generation PHP FrameworkSymony2 A Next Generation PHP Framework
Symony2 A Next Generation PHP Framework
 
Pluggable Django Application Patterns PyCon 2011
Pluggable Django Application Patterns PyCon 2011Pluggable Django Application Patterns PyCon 2011
Pluggable Django Application Patterns PyCon 2011
 
The Fast, The Slow and the Lazy
The Fast, The Slow and the LazyThe Fast, The Slow and the Lazy
The Fast, The Slow and the Lazy
 

Plus de Mikko Ohtamaa

Websauna - introduction to the best Python web framework
Websauna - introduction to the best Python web frameworkWebsauna - introduction to the best Python web framework
Websauna - introduction to the best Python web frameworkMikko Ohtamaa
 
Operations Security - SF Bitcoin Hackday March 2015
Operations Security - SF Bitcoin Hackday March 2015Operations Security - SF Bitcoin Hackday March 2015
Operations Security - SF Bitcoin Hackday March 2015Mikko Ohtamaa
 
Operations security - SyPy Dec 2014 (Sydney Python users)
Operations security - SyPy Dec 2014 (Sydney Python users)Operations security - SyPy Dec 2014 (Sydney Python users)
Operations security - SyPy Dec 2014 (Sydney Python users)Mikko Ohtamaa
 
Operations security (OPSEC)
Operations security (OPSEC)Operations security (OPSEC)
Operations security (OPSEC)Mikko Ohtamaa
 
Plone, battle-scarred community with battle tanks
Plone, battle-scarred community with battle tanksPlone, battle-scarred community with battle tanks
Plone, battle-scarred community with battle tanksMikko Ohtamaa
 
World Plone Day 2013
World Plone Day 2013World Plone Day 2013
World Plone Day 2013Mikko Ohtamaa
 
Solving problems one Plone package at a time
Solving problems one Plone package at a timeSolving problems one Plone package at a time
Solving problems one Plone package at a timeMikko Ohtamaa
 
Saving Plone from Plone agony
Saving Plone from Plone agonySaving Plone from Plone agony
Saving Plone from Plone agonyMikko Ohtamaa
 
Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
 Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ... Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...Mikko Ohtamaa
 
VVV validation and linting tool
VVV validation and linting toolVVV validation and linting tool
VVV validation and linting toolMikko Ohtamaa
 
Plone IDE - the future of Plone development
Plone IDE - the future of Plone developmentPlone IDE - the future of Plone development
Plone IDE - the future of Plone developmentMikko Ohtamaa
 
The Easy Way - Plone Conference 2011
The Easy Way - Plone Conference 2011The Easy Way - Plone Conference 2011
The Easy Way - Plone Conference 2011Mikko Ohtamaa
 
Mobile Landscape 2011
Mobile Landscape 2011Mobile Landscape 2011
Mobile Landscape 2011Mikko Ohtamaa
 
Mobiilimarkkinoinnin mahdollisuudet nyt
Mobiilimarkkinoinnin mahdollisuudet nytMobiilimarkkinoinnin mahdollisuudet nyt
Mobiilimarkkinoinnin mahdollisuudet nytMikko Ohtamaa
 
The World Outside Plone
The World Outside PloneThe World Outside Plone
The World Outside PloneMikko Ohtamaa
 
mFabrik Case Studies
mFabrik Case StudiesmFabrik Case Studies
mFabrik Case StudiesMikko Ohtamaa
 
Building HTML based mobile phone applications
Building HTML based mobile phone applicationsBuilding HTML based mobile phone applications
Building HTML based mobile phone applicationsMikko Ohtamaa
 

Plus de Mikko Ohtamaa (19)

Websauna - introduction to the best Python web framework
Websauna - introduction to the best Python web frameworkWebsauna - introduction to the best Python web framework
Websauna - introduction to the best Python web framework
 
Operations Security - SF Bitcoin Hackday March 2015
Operations Security - SF Bitcoin Hackday March 2015Operations Security - SF Bitcoin Hackday March 2015
Operations Security - SF Bitcoin Hackday March 2015
 
Operations security - SyPy Dec 2014 (Sydney Python users)
Operations security - SyPy Dec 2014 (Sydney Python users)Operations security - SyPy Dec 2014 (Sydney Python users)
Operations security - SyPy Dec 2014 (Sydney Python users)
 
Operations security (OPSEC)
Operations security (OPSEC)Operations security (OPSEC)
Operations security (OPSEC)
 
Plone, battle-scarred community with battle tanks
Plone, battle-scarred community with battle tanksPlone, battle-scarred community with battle tanks
Plone, battle-scarred community with battle tanks
 
World Plone Day 2013
World Plone Day 2013World Plone Day 2013
World Plone Day 2013
 
Test lol
Test lolTest lol
Test lol
 
Writing the docs
Writing the docsWriting the docs
Writing the docs
 
Solving problems one Plone package at a time
Solving problems one Plone package at a timeSolving problems one Plone package at a time
Solving problems one Plone package at a time
 
Saving Plone from Plone agony
Saving Plone from Plone agonySaving Plone from Plone agony
Saving Plone from Plone agony
 
Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
 Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ... Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
 
VVV validation and linting tool
VVV validation and linting toolVVV validation and linting tool
VVV validation and linting tool
 
Plone IDE - the future of Plone development
Plone IDE - the future of Plone developmentPlone IDE - the future of Plone development
Plone IDE - the future of Plone development
 
The Easy Way - Plone Conference 2011
The Easy Way - Plone Conference 2011The Easy Way - Plone Conference 2011
The Easy Way - Plone Conference 2011
 
Mobile Landscape 2011
Mobile Landscape 2011Mobile Landscape 2011
Mobile Landscape 2011
 
Mobiilimarkkinoinnin mahdollisuudet nyt
Mobiilimarkkinoinnin mahdollisuudet nytMobiilimarkkinoinnin mahdollisuudet nyt
Mobiilimarkkinoinnin mahdollisuudet nyt
 
The World Outside Plone
The World Outside PloneThe World Outside Plone
The World Outside Plone
 
mFabrik Case Studies
mFabrik Case StudiesmFabrik Case Studies
mFabrik Case Studies
 
Building HTML based mobile phone applications
Building HTML based mobile phone applicationsBuilding HTML based mobile phone applications
Building HTML based mobile phone applications
 

Dernier

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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
 
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
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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
 
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 BusinessPixlogix Infotech
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
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 2024The Digital Insurer
 
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
 
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
 
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
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Dernier (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
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
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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...
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
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
 
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
 
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
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Avoid bad Javascript with RequireJS, ECMAScript5 and strict mode

  • 1. Javascript - Avoiding the bad parts Mikko Ohtamaa mikko@opensourcehacker.com http://opensourcehacker.com http://twitter.com/moo9000 Saturday, November 5, 2011
  • 2. Lighting talk of 5 min Turn Python gurus to JS gurus Plone Conference 2011 Saturday, November 5, 2011
  • 3. Javascript has become better Don’t write Javascript like it was 1996 Saturday, November 5, 2011
  • 4. What your every JS file should look like Saturday, November 5, 2011
  • 5. /*global require,define,window,console*/ // Main require(["jquery", "domready!", "submodule"], function($, domready, submodule) { "use strict"; $("a").click(function() { var val = submodule.foobar(); window.alert(val); }); }); Saturday, November 5, 2011
  • 6. /*global require,define,window,console*/ // Submodule define(["jquery", "myothermodule"], function($, myothermodule) { 'use strict'; // Export public module API return { foobar : function() { return 1+1+myothermodule.func(); } }; }); Saturday, November 5, 2011
  • 7. Use require.js • AMD (Asynchronous Module Definition) • a.k.a. import for Javascript • Dependency solving • Automatic compression and merging of needed and only needed JS files using require.js optimizer Saturday, November 5, 2011
  • 8. Use ECMAScript5 • Goodies: this.function.bind(), Array.forEach() • Backwards compatibility (Internet Explorer): http://bit.ly/es5shim Saturday, November 5, 2011
  • 9. “use strict”; Enforces no global variables by default and fixes some other bad language features Saturday, November 5, 2011
  • 10. Enforce background JSLint checking in your text editor ... or JSLint modern fork, JSHint Saturday, November 5, 2011
  • 12. // Some JSLint hinting /*global window,console*/ Saturday, November 5, 2011
  • 13. Never use Javascript inline in HTML Saturday, November 5, 2011
  • 14. <a href=”#” onclick=”aargh()”> No Saturday, November 5, 2011
  • 15. // On page load $("a#handler").click(function() { // do stuff }); // For dynamic content // (AJAX loaded) $("#handler").live(function() { // do stuff }); Saturday, November 5, 2011
  • 16. Passing a bound method to an event handler using function.bind() Saturday, November 5, 2011
  • 17. function FooClass(){ } FooClass.prototype.myfunc = function(arg1,arg2) { } var f = new Foo(); // Bind arguments are this, arg1, arg2 setTimeout(f.myfunc.bind(f, "arg1", "arg2"), 10); Saturday, November 5, 2011
  • 18. Finding Javascript info • Use Mozilla Developer Network: “MDN Javascript bind” • Put w3school.com on ban-list - only bad information there Saturday, November 5, 2011
  • 19. Conclusion • Worst JS farts have been fixed / can be worked around with discipline • Javascript still lacks syntatic sugar, is not wrist friendly (boo!) • Mozilla et. al. are working on to fix that (but Philip didn’t promise do drop curly brackets or semicolons) Saturday, November 5, 2011