SlideShare una empresa de Scribd logo
1 de 17
Descargar para leer sin conexión
#1




Introducing Modern JavaScript
Modern JavaScript Programming
                         Doc. v. 0.1 - 25/03/09




       Wildan Maulana | wildan [at] tobethink.com
Object-Oriented JavaScript
// The constructor for our 'Lecture'
// Takes two strings, name and teacher
function Lecture( name, teacher ) {
    // Save them as local properties of the object
    this.name = name;
    this.teacher = teacher;
}

// A method of the Lecture class, used to generate
// a string that can be used to display Lecture information
Lecture.prototype.display = function(){
    return this.teacher + quot; is teaching quot; + this.name;
};

// A Schedule constructor that takes in an
// array of lectures
                                  // A method for constructing a string representing
function Schedule( lectures ) {
                                  // a Schedule of Lectures
    this.lectures = lectures;
                                  Schedule.prototype.display = function(){
}
                                      var str = quot;quot;;

                                      // Go through each of the lectures, building up
                                      // a string of information
                                      for ( var i = 0; i < this.lectures.length; i++ )
                                          str += this.lectures[i].display() + quot; quot;;

                                      return str;
                                 };
Using the Class
// Create a new Schedule object and save it in
// the variable 'mySchedule'
var mySchedule = new Schedule([
    // Create an array of the Lecture objects, which
    // are passed in as the only argument to the Lecture object
    new Lecture( quot;Gymquot;, quot;Mr. Smithquot; ),
    new Lecture( quot;Mathquot;, quot;Mrs. Jonesquot; ),
    new Lecture( quot;Englishquot;, quot;TBDquot; )
]);

// Display the Schedule information as a pop-up alert
alert( mySchedule.display() );
Testing Your Code
• Use Firebug plug-in for Firefox
Packaging for Distribution
• Use namespace to avoid conflict with
  other library
  – For example : public interface library
    developed by Yahoo

      // Add a mouseover event listener to the element that has an
      // ID of 'body'
      YAHOO.util.Event.addListener('body','mouseover',function(){

            // and change the background color of the element to red
            this.style.backgroundColor = 'red';

      });
Unobtrusive DOM Scripting
• Writing unobtrusive code implies a
  complete separation of your HTML
  content: the data coming from the
  server, and the JavaScript code used
  to make it all dynamic
• Writing modern, unobtrusive code
  consists of two aspects : the
  Document Object Model (DOM), and
  JavaScript events
The Document Object Model
• The DOM was constructed to provide
  an intuitive way for developers to
  navigate an XML hierarchy (remember
  : valid HTML is simply a subset of
  XML)
• Next : Using DOM to Locate and
  Manipulate Different DOM Elements
<html>
<head>
    <title>Introduction to the DOM</title>
    <script>
    // We can't manipulate the DOM until the document
    // is fully loaded
    window.onload = function(){

       // Find all the <li> elements in the document
       var li = document.getElementsByTagName('li');

       // and add a ared border around all of them
       for ( var j = 0; j < li.length; j++ ) {
           li[j].style.border = '1px solid #000';
       }

       // Locate the element with an ID of 'everywhere'
       var every = document.getElementById( quot;everywherequot; );

       // and remove it from the document
       every.parentNode.removeChild( every );

    };
    </script>
</head>
<body>
    <h1>Introduction to the DOM</h1>
    <p class=quot;testquot;>There are a number of reasons why the DOM is awesome, here are some:</p>
    <ul>
        <li id=quot;everywherequot;>It can be found everywhere.</li>
        <li class=quot;testquot;>It's easy to use.</li>
        <li class=quot;testquot;>It can help you to find what you want, really quickly.</li>
    </ul>
</body>
</html>
Events
• Events are the glue that holds together all
  user interaction within an application
• JavaScript events are complex and diverse
<html>
<head>
    <title>Introduction to the DOM</title>
    <script>
    // We can't manipulate the DOM until the document
    // is fully loaded
    window.onload = function(){

       // Find all the <li> elements, to attach the event handlers to them
       var li = document.getElementsByTagName('li');
       for ( var i = 0; i < li.length; i++ ) {

           // Attach a mouseover event handler to the <li> element,
           // which changes the <li>s background to blue.
           li[i].onmouseover = function() {
               this.style.backgroundColor = 'blue';
           };

           // Attach a mouseout event handler to the <li> element
           // which changes the <li>s background back to its default white
           li[i].onmouseout = function() {
               this.style.backgroundColor = 'white';
           };

       }

    };
    </script>
</head>
<body>
    <h1>Introduction to the DOM</h1>
    <p class='test'>There are a number of reasons why the DOM is awesome, here are some:</p>
    <ul>
        <li id='everywhere'>It can be found everywhere.</li>
        <li class='test'>It's easy to use.</li>
        <li class='test'>It can help you to find what you want, really quickly.</li>
    </ul>
</body>
</html>
JavaScript and CSS
Cascading style sheets (CSS) serve as the standard for
laying out simple, unobtrusive web pages that still afford you
(the developer) the greatest amount of power while providing your
users with the least amount of compatibility issues.
Ultimately, dynamic HTML is about exploring what can be
achieved when JavaScript and CSS interact with each other
and how you can best use that combination
to create impressive results.
Ajax
• Ajax, or Asynchronous JavaScript and XML, is a
  term coined in the article “Ajax: A New Approach
  to Web
  Applications”(http://www.adaptivepath.com/public
  ations/essays/archives/000385.php) by Jesse James
  Garrett
• The term Ajax encompasses hundreds of
  permutations for data communication, but all
  center around a central premise: that additional
  requests are made from the client to
  the server even after the page has completely
  loaded
Browser Support
• http://developer.yahoo.com/yui/articles/gbs/gbs.html
Consistent Development Based - Features
    Core JavaScript 1.5: The most current, accepted version of
•
    JavaScript. It has all the features necessary to support fully
    functional object-oriented JavaScript. Internet Explorer 5.0 doesn’t
    support full 1.5, which is the primary reason developers don’t like
    to support it.
    XML Document Object Model (DOM) 2: The standard for traversing
•
    HTML and XML documents. This is absolutely essential for writing
    fast applications.
    XMLHttpRequest: The backbone of Ajax—a simple layer for initiating
•
    remote HTTP requests. All browsers support this object by default,
    except for Internet Explorer 5.5–6.0; however, they each support
    initiating a comparable object using ActiveX.
    CSS: An essential requirement for designing web pages. This may
•
    seem like an odd requirement, but having CSS is essential for web
    application developers. Since every modern browser supports CSS,
    it generally boils down to discrepancies in presentation that cause
    the most problems. This is the primary reason Internet Explorer for
    Mac is less frequently supported.
Q&A
Reference
• Pro JavaScript Techniques, John Resig,
  Apress

Más contenido relacionado

La actualidad más candente

JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)
Nicholas Zakas
 

La actualidad más candente (20)

Maintainable JavaScript 2011
Maintainable JavaScript 2011Maintainable JavaScript 2011
Maintainable JavaScript 2011
 
JavaScript Good Practices
JavaScript Good PracticesJavaScript Good Practices
JavaScript Good Practices
 
Object Oriented Javascript
Object Oriented JavascriptObject Oriented Javascript
Object Oriented Javascript
 
JavaScript Best Pratices
JavaScript Best PraticesJavaScript Best Pratices
JavaScript Best Pratices
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To Closure
 
jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]
 
Advanced JavaScript - Internship Presentation - Week6
Advanced JavaScript - Internship Presentation - Week6Advanced JavaScript - Internship Presentation - Week6
Advanced JavaScript - Internship Presentation - Week6
 
jQuery
jQueryjQuery
jQuery
 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScript
 
JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)
 
Java script
Java scriptJava script
Java script
 
JavaScript OOPs
JavaScript OOPsJavaScript OOPs
JavaScript OOPs
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
Javascript and Jquery Best practices
Javascript and Jquery Best practicesJavascript and Jquery Best practices
Javascript and Jquery Best practices
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulation
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 

Similar a Modern JavaScript Programming

the next web now
the next web nowthe next web now
the next web now
zulin Gu
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
Hugo Hamon
 
Enhance Web Performance
Enhance Web PerformanceEnhance Web Performance
Enhance Web Performance
Adam Lu
 

Similar a Modern JavaScript Programming (20)

eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
 
HTML5
HTML5HTML5
HTML5
 
Scripting The Dom
Scripting The DomScripting The Dom
Scripting The Dom
 
Javascript Templating
Javascript TemplatingJavascript Templating
Javascript Templating
 
UNO based ODF Toolkit API
UNO based ODF Toolkit APIUNO based ODF Toolkit API
UNO based ODF Toolkit API
 
the next web now
the next web nowthe next web now
the next web now
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
jQuery
jQueryjQuery
jQuery
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
 
jQuery Presentation - Refresh Events
jQuery Presentation - Refresh EventsjQuery Presentation - Refresh Events
jQuery Presentation - Refresh Events
 
Eugene Andruszczenko: jQuery
Eugene Andruszczenko: jQueryEugene Andruszczenko: jQuery
Eugene Andruszczenko: jQuery
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
Enhance Web Performance
Enhance Web PerformanceEnhance Web Performance
Enhance Web Performance
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScript
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
 
JS basics
JS basicsJS basics
JS basics
 
Client-side JavaScript Vulnerabilities
Client-side JavaScript VulnerabilitiesClient-side JavaScript Vulnerabilities
Client-side JavaScript Vulnerabilities
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
 
DWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A TutorialDWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A Tutorial
 

Más de Wildan Maulana

Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
Wildan Maulana
 
Pengembangan OpenThink SAS 2013-2014
Pengembangan OpenThink SAS 2013-2014Pengembangan OpenThink SAS 2013-2014
Pengembangan OpenThink SAS 2013-2014
Wildan Maulana
 
ICA – AtoM : Retensi Arsip
ICA – AtoM : Retensi ArsipICA – AtoM : Retensi Arsip
ICA – AtoM : Retensi Arsip
Wildan Maulana
 
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RWOpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
Wildan Maulana
 
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
Wildan Maulana
 
PostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
PostgreSQL BootCamp : Manajemen Master Data dengan SkyToolsPostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
PostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
Wildan Maulana
 
Mensetup Google Apps sebagai IdP jenis openID dan Aplikasi Berbasis CakePHP ...
Mensetup Google Apps sebagai IdP jenis openID  dan Aplikasi Berbasis CakePHP ...Mensetup Google Apps sebagai IdP jenis openID  dan Aplikasi Berbasis CakePHP ...
Mensetup Google Apps sebagai IdP jenis openID dan Aplikasi Berbasis CakePHP ...
Wildan Maulana
 
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai SpMensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
Wildan Maulana
 
Konfigurasi simpleSAMLphp dengan Google Apps Sebagai Identity Provider
Konfigurasi simpleSAMLphp  dengan Google Apps Sebagai Identity ProviderKonfigurasi simpleSAMLphp  dengan Google Apps Sebagai Identity Provider
Konfigurasi simpleSAMLphp dengan Google Apps Sebagai Identity Provider
Wildan Maulana
 
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
Wildan Maulana
 
Instalasi dan Konfigurasi simpleSAMLphp
Instalasi dan Konfigurasi simpleSAMLphpInstalasi dan Konfigurasi simpleSAMLphp
Instalasi dan Konfigurasi simpleSAMLphp
Wildan Maulana
 
River Restoration in Asia and Connection Between IWRM and River Restoration
River Restoration in Asia and Connection Between IWRM and River RestorationRiver Restoration in Asia and Connection Between IWRM and River Restoration
River Restoration in Asia and Connection Between IWRM and River Restoration
Wildan Maulana
 
Penilaian Siswa di Finlandia - Pendidikan Dasar
Penilaian Siswa di Finlandia - Pendidikan DasarPenilaian Siswa di Finlandia - Pendidikan Dasar
Penilaian Siswa di Finlandia - Pendidikan Dasar
Wildan Maulana
 
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and UsesProyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
Wildan Maulana
 
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang TuaOpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
Wildan Maulana
 

Más de Wildan Maulana (20)

Hasil Pendataan Potensi Desa 2018
Hasil Pendataan Potensi Desa 2018Hasil Pendataan Potensi Desa 2018
Hasil Pendataan Potensi Desa 2018
 
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
 
Ketahanan Pangan #1 : Gerakan Sekolah Menanam Melon
Ketahanan Pangan #1 : Gerakan Sekolah Menanam MelonKetahanan Pangan #1 : Gerakan Sekolah Menanam Melon
Ketahanan Pangan #1 : Gerakan Sekolah Menanam Melon
 
Pengembangan OpenThink SAS 2013-2014
Pengembangan OpenThink SAS 2013-2014Pengembangan OpenThink SAS 2013-2014
Pengembangan OpenThink SAS 2013-2014
 
ICA – AtoM : Retensi Arsip
ICA – AtoM : Retensi ArsipICA – AtoM : Retensi Arsip
ICA – AtoM : Retensi Arsip
 
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RWOpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
 
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
 
PostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
PostgreSQL BootCamp : Manajemen Master Data dengan SkyToolsPostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
PostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
 
Mensetup Google Apps sebagai IdP jenis openID dan Aplikasi Berbasis CakePHP ...
Mensetup Google Apps sebagai IdP jenis openID  dan Aplikasi Berbasis CakePHP ...Mensetup Google Apps sebagai IdP jenis openID  dan Aplikasi Berbasis CakePHP ...
Mensetup Google Apps sebagai IdP jenis openID dan Aplikasi Berbasis CakePHP ...
 
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai SpMensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
 
Konfigurasi simpleSAMLphp dengan Google Apps Sebagai Identity Provider
Konfigurasi simpleSAMLphp  dengan Google Apps Sebagai Identity ProviderKonfigurasi simpleSAMLphp  dengan Google Apps Sebagai Identity Provider
Konfigurasi simpleSAMLphp dengan Google Apps Sebagai Identity Provider
 
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
 
Instalasi dan Konfigurasi simpleSAMLphp
Instalasi dan Konfigurasi simpleSAMLphpInstalasi dan Konfigurasi simpleSAMLphp
Instalasi dan Konfigurasi simpleSAMLphp
 
River Restoration in Asia and Connection Between IWRM and River Restoration
River Restoration in Asia and Connection Between IWRM and River RestorationRiver Restoration in Asia and Connection Between IWRM and River Restoration
River Restoration in Asia and Connection Between IWRM and River Restoration
 
Optimasi Limpasan Air Limbah Ke Kali Surabaya (Segmen Sepanjang – Jagir) De...
Optimasi Limpasan Air Limbah  Ke Kali Surabaya (Segmen Sepanjang – Jagir)  De...Optimasi Limpasan Air Limbah  Ke Kali Surabaya (Segmen Sepanjang – Jagir)  De...
Optimasi Limpasan Air Limbah Ke Kali Surabaya (Segmen Sepanjang – Jagir) De...
 
Penilaian Siswa di Finlandia - Pendidikan Dasar
Penilaian Siswa di Finlandia - Pendidikan DasarPenilaian Siswa di Finlandia - Pendidikan Dasar
Penilaian Siswa di Finlandia - Pendidikan Dasar
 
Statistik Listrik
Statistik ListrikStatistik Listrik
Statistik Listrik
 
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and UsesProyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
 
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang TuaOpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
 
Menggunakan AlisJK : Equating
Menggunakan AlisJK : EquatingMenggunakan AlisJK : Equating
Menggunakan AlisJK : Equating
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+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@
 

Último (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
+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...
 
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
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
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...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

Modern JavaScript Programming

  • 1. #1 Introducing Modern JavaScript Modern JavaScript Programming Doc. v. 0.1 - 25/03/09 Wildan Maulana | wildan [at] tobethink.com
  • 2. Object-Oriented JavaScript // The constructor for our 'Lecture' // Takes two strings, name and teacher function Lecture( name, teacher ) { // Save them as local properties of the object this.name = name; this.teacher = teacher; } // A method of the Lecture class, used to generate // a string that can be used to display Lecture information Lecture.prototype.display = function(){ return this.teacher + quot; is teaching quot; + this.name; }; // A Schedule constructor that takes in an // array of lectures // A method for constructing a string representing function Schedule( lectures ) { // a Schedule of Lectures this.lectures = lectures; Schedule.prototype.display = function(){ } var str = quot;quot;; // Go through each of the lectures, building up // a string of information for ( var i = 0; i < this.lectures.length; i++ ) str += this.lectures[i].display() + quot; quot;; return str; };
  • 3. Using the Class // Create a new Schedule object and save it in // the variable 'mySchedule' var mySchedule = new Schedule([ // Create an array of the Lecture objects, which // are passed in as the only argument to the Lecture object new Lecture( quot;Gymquot;, quot;Mr. Smithquot; ), new Lecture( quot;Mathquot;, quot;Mrs. Jonesquot; ), new Lecture( quot;Englishquot;, quot;TBDquot; ) ]); // Display the Schedule information as a pop-up alert alert( mySchedule.display() );
  • 4. Testing Your Code • Use Firebug plug-in for Firefox
  • 5. Packaging for Distribution • Use namespace to avoid conflict with other library – For example : public interface library developed by Yahoo // Add a mouseover event listener to the element that has an // ID of 'body' YAHOO.util.Event.addListener('body','mouseover',function(){ // and change the background color of the element to red this.style.backgroundColor = 'red'; });
  • 6. Unobtrusive DOM Scripting • Writing unobtrusive code implies a complete separation of your HTML content: the data coming from the server, and the JavaScript code used to make it all dynamic • Writing modern, unobtrusive code consists of two aspects : the Document Object Model (DOM), and JavaScript events
  • 7. The Document Object Model • The DOM was constructed to provide an intuitive way for developers to navigate an XML hierarchy (remember : valid HTML is simply a subset of XML) • Next : Using DOM to Locate and Manipulate Different DOM Elements
  • 8. <html> <head> <title>Introduction to the DOM</title> <script> // We can't manipulate the DOM until the document // is fully loaded window.onload = function(){ // Find all the <li> elements in the document var li = document.getElementsByTagName('li'); // and add a ared border around all of them for ( var j = 0; j < li.length; j++ ) { li[j].style.border = '1px solid #000'; } // Locate the element with an ID of 'everywhere' var every = document.getElementById( quot;everywherequot; ); // and remove it from the document every.parentNode.removeChild( every ); }; </script> </head> <body> <h1>Introduction to the DOM</h1> <p class=quot;testquot;>There are a number of reasons why the DOM is awesome, here are some:</p> <ul> <li id=quot;everywherequot;>It can be found everywhere.</li> <li class=quot;testquot;>It's easy to use.</li> <li class=quot;testquot;>It can help you to find what you want, really quickly.</li> </ul> </body> </html>
  • 9. Events • Events are the glue that holds together all user interaction within an application • JavaScript events are complex and diverse
  • 10. <html> <head> <title>Introduction to the DOM</title> <script> // We can't manipulate the DOM until the document // is fully loaded window.onload = function(){ // Find all the <li> elements, to attach the event handlers to them var li = document.getElementsByTagName('li'); for ( var i = 0; i < li.length; i++ ) { // Attach a mouseover event handler to the <li> element, // which changes the <li>s background to blue. li[i].onmouseover = function() { this.style.backgroundColor = 'blue'; }; // Attach a mouseout event handler to the <li> element // which changes the <li>s background back to its default white li[i].onmouseout = function() { this.style.backgroundColor = 'white'; }; } }; </script> </head> <body> <h1>Introduction to the DOM</h1> <p class='test'>There are a number of reasons why the DOM is awesome, here are some:</p> <ul> <li id='everywhere'>It can be found everywhere.</li> <li class='test'>It's easy to use.</li> <li class='test'>It can help you to find what you want, really quickly.</li> </ul> </body> </html>
  • 11. JavaScript and CSS Cascading style sheets (CSS) serve as the standard for laying out simple, unobtrusive web pages that still afford you (the developer) the greatest amount of power while providing your users with the least amount of compatibility issues. Ultimately, dynamic HTML is about exploring what can be achieved when JavaScript and CSS interact with each other and how you can best use that combination to create impressive results.
  • 12. Ajax • Ajax, or Asynchronous JavaScript and XML, is a term coined in the article “Ajax: A New Approach to Web Applications”(http://www.adaptivepath.com/public ations/essays/archives/000385.php) by Jesse James Garrett • The term Ajax encompasses hundreds of permutations for data communication, but all center around a central premise: that additional requests are made from the client to the server even after the page has completely loaded
  • 13.
  • 15. Consistent Development Based - Features Core JavaScript 1.5: The most current, accepted version of • JavaScript. It has all the features necessary to support fully functional object-oriented JavaScript. Internet Explorer 5.0 doesn’t support full 1.5, which is the primary reason developers don’t like to support it. XML Document Object Model (DOM) 2: The standard for traversing • HTML and XML documents. This is absolutely essential for writing fast applications. XMLHttpRequest: The backbone of Ajax—a simple layer for initiating • remote HTTP requests. All browsers support this object by default, except for Internet Explorer 5.5–6.0; however, they each support initiating a comparable object using ActiveX. CSS: An essential requirement for designing web pages. This may • seem like an odd requirement, but having CSS is essential for web application developers. Since every modern browser supports CSS, it generally boils down to discrepancies in presentation that cause the most problems. This is the primary reason Internet Explorer for Mac is less frequently supported.
  • 16. Q&A
  • 17. Reference • Pro JavaScript Techniques, John Resig, Apress