SlideShare una empresa de Scribd logo
1 de 25
INTRODUCTION
TO JAVASCRIPT


DMD12 BSc
10th February 2011
Syd Lawrence                 SIT BACK /
                             SIT BACK
                             LISTEN UP
                             LISTEN UP

slideshare.net/sydlawrence
WHAT
IS IT?


                                                        SIT BACK /
                                                        SIT BACK
                                                        LISTEN UP
                                                        LISTEN UP

http://www.flickr.com/photos/steve_chilton/1517222734
HTML



                                                SIT BACK /
                                                SIT BACK
                                                LISTEN UP
                                                LISTEN UP

http://www.flickr.com/photos/oskay/265899865/
CSS



                                                      SIT BACK /
                                                      SIT BACK
                                                      LISTEN UP
                                                      LISTEN UP

http://www.flickr.com/photos/creepstreeps/81346047/
JAVASCRIPT



                                                      SIT BACK /
                                                      SIT BACK
                                                      LISTEN UP
                                                      LISTEN UP

http://www.flickr.com/photos/veggiefrog/2573076568/
SIT BACK /
SIT BACK
LISTEN UP
LISTEN UP
SIT BACK /
                                                          SIT BACK
                                                          LISTEN UP
                                                          LISTEN UP

http://www.flickr.com/photos/executionsinfo/4573848874/
SYDLAWRENCE.COM



                  SIT BACK /
                  SIT BACK
                  LISTEN UP
                  LISTEN UP

Victorian Times
HOW?
https://gist.github.com/817379




                                                      SIT BACK /
                                                      SIT BACK
                                                      LISTEN UP
                                                      LISTEN UP

http://www.flickr.com/photos/9550033@N04/4298402206
<script
    type=”text/javascript”
    src=”script.js”>
</script>


                        SIT BACK /
                        SIT BACK
                        LISTEN UP
                        LISTEN UP
// standard variables
var foo = “bar”;

// when the window is ready (event listener)
document.onready = function(event) {
  /* do something */
}

// define a method
function foo(bar) {
   alert(bar);
}

// boolean expressions
if (foo == "bar") {
  /* do something */
}

// array
var arr = ['a','b','c','d'];

// retrieving an element by id i.e. <div       SIT BACK /
                                               SIT BACK
                                               LISTEN UP
                                               LISTEN UP
id='element'></div>
var el = document.getElementById('element');
// associative array
var assoc = {
  name: 'syd',
  email: 'syd@sydlawrence.com'
};

// object
var obj = {
  name: 'syd',
  email: 'syd@sydlawrence.com'
};

// for loops
for (i in assoc) {

  /* do something with assoc[i]; */
  console.log(assoc[i]);
}

// retrieving an element by css selectors i.e. <div class='element'></div>
var el = document.querySelector('.element');

                                                                  SIT BACK /
                                                                  SIT BACK
                                                                  LISTEN UP
                                                                  LISTEN UP
DEBUGGING
// similar to actionscript's trace method
console.log(obj);

// try catch
try {
  /* do something */
}
catch(e) {
  /* an exception has been caught */
}
                                            SIT BACK /
                                            SIT BACK
                                            LISTEN UP
                                            LISTEN UP
COMMON
MISTAKES


                                                 SIT BACK /
                                                 SIT BACK
                                                 LISTEN UP
                                                 LISTEN UP

http://www.flickr.com/photos/plucker/17269246/
// THIS WILL THROW AN ERROR IN INTERNET EXPLORER

var obj = {
  a:‘a’,
  b:’b’,      // remove the final ,
}



make sure the element has loaded before you try to
manipulate it.

Not all browsers have console.log

style.camelCase
el.style.backgroundColor = ‘#00ff00’;

                                                     SIT BACK /
                                                     SIT BACK
                                                     LISTEN UP
                                                     LISTEN UP
CLASSES ARE
FUNCTIONS TOO



                                                 SIT BACK /
                                                 SIT BACK
                                                 LISTEN UP
                                                 LISTEN UP

http://www.flickr.com/photos/jiuck/4365662437/
function Person() {

 this.first_name = "Syd";

 this.last_name = "Lawrence";

 this.email = "syd@sydlawrence.com";


 this.fullName = function() {

 
 return this.first_name + " " + this.last_name;

 }
}

var person = new Person();

// this will return "Syd Lawrence";
var full_name = person.fullName();




                                                     SIT BACK /
                                                     SIT BACK
                                                     LISTEN UP
                                                     LISTEN UP
function Person() {

 this.first_name = "Syd";

 this.last_name = "Lawrence";

 this.email = "syd@sydlawrence.com";


 this.fullName = function() {

 
 return this.first_name + " " + this.last_name;

 }
}

var person = new Person();
var person2 = new Person();

// rename the first person
person.first_name = "Bob";

// this will return "Bob Lawrence";
person.fullName();

// this will return "Syd Lawrence";
person2.fullName();

                                                     SIT BACK /
                                                     SIT BACK
                                                     LISTEN UP
                                                     LISTEN UP
PROTOTYPE



                                                  SIT BACK /
                                                  SIT BACK
                                                  LISTEN UP
                                                  LISTEN UP

http://www.flickr.com/photos/hugo90/4070460675/
//First, create the custom object "circle"
function circle(){
}

circle.prototype.pi=3.14159;

// create the object method
circle.prototype.alertpi = function(){
    alert(this.pi);
}




                                             SIT BACK /
                                             SIT BACK
                                             LISTEN UP
                                             LISTEN UP
CALLBACKS



                                               SIT BACK /
                                               SIT BACK
                                               LISTEN UP
                                               LISTEN UP

http://www.flickr.com/photos/splorp/64027565
function Object() {


 this.runMethod = function(fn) {

 
 var data = "hi";

 
 fn(data);

 }
}

var object = new Object();

object.runMethod(function(data) {

 alert(data);
});




                                    SIT BACK /
                                    SIT BACK
                                    LISTEN UP
                                    LISTEN UP
function Object() {


 this.runMethod = function(fn) {

 
 var data = "world";

 
 fn(data);

 }
}

var object = new Object();

function alertData(data) {

 alert(data);
}

object.runMethod(alertData);


                                    SIT BACK /
                                    SIT BACK
                                    LISTEN UP
                                    LISTEN UP
WANT TO
KNOW MORE

http://www.javascriptkit.com
http://dailyjs.com/

Books
Simply Javascript: Everyting You Need To Learn Javascript From Scratch
                                                                         SIT BACK /
                                                                         SIT BACK
The JavaScript Anthology                                                 LISTEN UP
                                                                         LISTEN UP

Buils Your Own Ajax Web Applications
A LITTLE
TASK DUE
17th FEB 2011
(TOTALLY OPTIONAL)




For next week’s lecture I want you to all have attempted to create an HTML page with
an image.
When you hover over the image, the image changes in some way.
When you move your mouse away it goes back to how it was.
                                                                                       SIT BACK /
                                                                                       SIT BACK
                                                                                       LISTEN UP
                                                                                       LISTEN UP

You may choose how the image changes

Más contenido relacionado

Más de Syd Lawrence

High Performance PhoneGap Apps
High Performance PhoneGap AppsHigh Performance PhoneGap Apps
High Performance PhoneGap AppsSyd Lawrence
 
Music is the Soul - The Web is the Platform FOWA London 2014
Music is the Soul - The Web is the Platform FOWA London 2014Music is the Soul - The Web is the Platform FOWA London 2014
Music is the Soul - The Web is the Platform FOWA London 2014Syd Lawrence
 
Mobile Apps with Web Tech
Mobile Apps with Web TechMobile Apps with Web Tech
Mobile Apps with Web TechSyd Lawrence
 
It's the start of the web revolution, but it's not what you think
It's the start of the web revolution, but it's not what you thinkIt's the start of the web revolution, but it's not what you think
It's the start of the web revolution, but it's not what you thinkSyd Lawrence
 
Rewriting The History Books
Rewriting The History BooksRewriting The History Books
Rewriting The History BooksSyd Lawrence
 
Mobile Web App Development (Becoming native)
Mobile Web App Development (Becoming native)Mobile Web App Development (Becoming native)
Mobile Web App Development (Becoming native)Syd Lawrence
 
Mobile Web App Development (Building your API)
Mobile Web App Development (Building your API)Mobile Web App Development (Building your API)
Mobile Web App Development (Building your API)Syd Lawrence
 
Mobile web app development
Mobile web app developmentMobile web app development
Mobile web app developmentSyd Lawrence
 
Making AJAX User Friendly, Google Friendly, Friendly Friendly using the Histo...
Making AJAX User Friendly, Google Friendly, Friendly Friendly using the Histo...Making AJAX User Friendly, Google Friendly, Friendly Friendly using the Histo...
Making AJAX User Friendly, Google Friendly, Friendly Friendly using the Histo...Syd Lawrence
 

Más de Syd Lawrence (9)

High Performance PhoneGap Apps
High Performance PhoneGap AppsHigh Performance PhoneGap Apps
High Performance PhoneGap Apps
 
Music is the Soul - The Web is the Platform FOWA London 2014
Music is the Soul - The Web is the Platform FOWA London 2014Music is the Soul - The Web is the Platform FOWA London 2014
Music is the Soul - The Web is the Platform FOWA London 2014
 
Mobile Apps with Web Tech
Mobile Apps with Web TechMobile Apps with Web Tech
Mobile Apps with Web Tech
 
It's the start of the web revolution, but it's not what you think
It's the start of the web revolution, but it's not what you thinkIt's the start of the web revolution, but it's not what you think
It's the start of the web revolution, but it's not what you think
 
Rewriting The History Books
Rewriting The History BooksRewriting The History Books
Rewriting The History Books
 
Mobile Web App Development (Becoming native)
Mobile Web App Development (Becoming native)Mobile Web App Development (Becoming native)
Mobile Web App Development (Becoming native)
 
Mobile Web App Development (Building your API)
Mobile Web App Development (Building your API)Mobile Web App Development (Building your API)
Mobile Web App Development (Building your API)
 
Mobile web app development
Mobile web app developmentMobile web app development
Mobile web app development
 
Making AJAX User Friendly, Google Friendly, Friendly Friendly using the Histo...
Making AJAX User Friendly, Google Friendly, Friendly Friendly using the Histo...Making AJAX User Friendly, Google Friendly, Friendly Friendly using the Histo...
Making AJAX User Friendly, Google Friendly, Friendly Friendly using the Histo...
 

Último

Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
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
 
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
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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 SavingEdi Saputra
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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 DiscoveryTrustArc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
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 Processorsdebabhi2
 
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 Takeoffsammart93
 

Último (20)

Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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...
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
+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...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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
 
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
 

Introduction to javascript

  • 1. INTRODUCTION TO JAVASCRIPT DMD12 BSc 10th February 2011 Syd Lawrence SIT BACK / SIT BACK LISTEN UP LISTEN UP slideshare.net/sydlawrence
  • 2. WHAT IS IT? SIT BACK / SIT BACK LISTEN UP LISTEN UP http://www.flickr.com/photos/steve_chilton/1517222734
  • 3. HTML SIT BACK / SIT BACK LISTEN UP LISTEN UP http://www.flickr.com/photos/oskay/265899865/
  • 4. CSS SIT BACK / SIT BACK LISTEN UP LISTEN UP http://www.flickr.com/photos/creepstreeps/81346047/
  • 5. JAVASCRIPT SIT BACK / SIT BACK LISTEN UP LISTEN UP http://www.flickr.com/photos/veggiefrog/2573076568/
  • 6. SIT BACK / SIT BACK LISTEN UP LISTEN UP
  • 7. SIT BACK / SIT BACK LISTEN UP LISTEN UP http://www.flickr.com/photos/executionsinfo/4573848874/
  • 8. SYDLAWRENCE.COM SIT BACK / SIT BACK LISTEN UP LISTEN UP Victorian Times
  • 9. HOW? https://gist.github.com/817379 SIT BACK / SIT BACK LISTEN UP LISTEN UP http://www.flickr.com/photos/9550033@N04/4298402206
  • 10. <script type=”text/javascript” src=”script.js”> </script> SIT BACK / SIT BACK LISTEN UP LISTEN UP
  • 11. // standard variables var foo = “bar”; // when the window is ready (event listener) document.onready = function(event) {   /* do something */ } // define a method function foo(bar) {    alert(bar); } // boolean expressions if (foo == "bar") {   /* do something */ } // array var arr = ['a','b','c','d']; // retrieving an element by id i.e. <div SIT BACK / SIT BACK LISTEN UP LISTEN UP id='element'></div> var el = document.getElementById('element');
  • 12. // associative array var assoc = {   name: 'syd',   email: 'syd@sydlawrence.com' }; // object var obj = {   name: 'syd',   email: 'syd@sydlawrence.com' }; // for loops for (i in assoc) {   /* do something with assoc[i]; */   console.log(assoc[i]); } // retrieving an element by css selectors i.e. <div class='element'></div> var el = document.querySelector('.element'); SIT BACK / SIT BACK LISTEN UP LISTEN UP
  • 13. DEBUGGING // similar to actionscript's trace method console.log(obj); // try catch try {   /* do something */ } catch(e) {   /* an exception has been caught */ } SIT BACK / SIT BACK LISTEN UP LISTEN UP
  • 14. COMMON MISTAKES SIT BACK / SIT BACK LISTEN UP LISTEN UP http://www.flickr.com/photos/plucker/17269246/
  • 15. // THIS WILL THROW AN ERROR IN INTERNET EXPLORER var obj = { a:‘a’, b:’b’, // remove the final , } make sure the element has loaded before you try to manipulate it. Not all browsers have console.log style.camelCase el.style.backgroundColor = ‘#00ff00’; SIT BACK / SIT BACK LISTEN UP LISTEN UP
  • 16. CLASSES ARE FUNCTIONS TOO SIT BACK / SIT BACK LISTEN UP LISTEN UP http://www.flickr.com/photos/jiuck/4365662437/
  • 17. function Person() { this.first_name = "Syd"; this.last_name = "Lawrence"; this.email = "syd@sydlawrence.com"; this.fullName = function() { return this.first_name + " " + this.last_name; } } var person = new Person(); // this will return "Syd Lawrence"; var full_name = person.fullName(); SIT BACK / SIT BACK LISTEN UP LISTEN UP
  • 18. function Person() { this.first_name = "Syd"; this.last_name = "Lawrence"; this.email = "syd@sydlawrence.com"; this.fullName = function() { return this.first_name + " " + this.last_name; } } var person = new Person(); var person2 = new Person(); // rename the first person person.first_name = "Bob"; // this will return "Bob Lawrence"; person.fullName(); // this will return "Syd Lawrence"; person2.fullName(); SIT BACK / SIT BACK LISTEN UP LISTEN UP
  • 19. PROTOTYPE SIT BACK / SIT BACK LISTEN UP LISTEN UP http://www.flickr.com/photos/hugo90/4070460675/
  • 20. //First, create the custom object "circle" function circle(){ } circle.prototype.pi=3.14159; // create the object method circle.prototype.alertpi = function(){ alert(this.pi); } SIT BACK / SIT BACK LISTEN UP LISTEN UP
  • 21. CALLBACKS SIT BACK / SIT BACK LISTEN UP LISTEN UP http://www.flickr.com/photos/splorp/64027565
  • 22. function Object() { this.runMethod = function(fn) { var data = "hi"; fn(data); } } var object = new Object(); object.runMethod(function(data) { alert(data); }); SIT BACK / SIT BACK LISTEN UP LISTEN UP
  • 23. function Object() { this.runMethod = function(fn) { var data = "world"; fn(data); } } var object = new Object(); function alertData(data) { alert(data); } object.runMethod(alertData); SIT BACK / SIT BACK LISTEN UP LISTEN UP
  • 24. WANT TO KNOW MORE http://www.javascriptkit.com http://dailyjs.com/ Books Simply Javascript: Everyting You Need To Learn Javascript From Scratch SIT BACK / SIT BACK The JavaScript Anthology LISTEN UP LISTEN UP Buils Your Own Ajax Web Applications
  • 25. A LITTLE TASK DUE 17th FEB 2011 (TOTALLY OPTIONAL) For next week’s lecture I want you to all have attempted to create an HTML page with an image. When you hover over the image, the image changes in some way. When you move your mouse away it goes back to how it was. SIT BACK / SIT BACK LISTEN UP LISTEN UP You may choose how the image changes

Notas del editor

  1. \n
  2. Javascript is not like java\n@adactio once said &amp;#x201C;Java is to Javascript as Ham is to Hamster&amp;#x201D;\n
  3. HTML is the building blocks that websites are made\nThey are &amp;#x2018;elements&amp;#x2019; of a web page\n
  4. CSS is the styling, the decorations of the website.\n
  5. So, we have a house. We have our HTML building blocks, and we have paint on the walls, and our sites are looking gooood :)\nWhy do we need javascript?\nThink of javascript as the electricity of the house. It makes things inside your house do stuff.\n
  6. BBC uses it over their site... but just as an example\nhome page, boxes minimise, move, add etc. etc.\n
  7. All over\nLogin box\nTop tweets\nTrending topics ticker\nThe list goes on\n
  8. I am so pleased I can use this slide again :)\n\nAs you guessed it most modern sites use javascript\n
  9. \n
  10. Include the javascript file in your html file\n
  11. \n
  12. \n
  13. Chrome Inspector or firefbug, or something similar... use it!\n
  14. There are various common mistakes made\n
  15. Adding an extra comma in an object\nremembering document.onready\nif (window.console)\ncamelCase styling\n
  16. Classes are functions too...\n
  17. \n
  18. \n
  19. The prototype object can also help you quickly add a custom method to an object that is reflected on all instances of it.\n
  20. Adding extra functions on to the class\n
  21. You can pass functions to other functions to act as callbacks.\n
  22. Passing a one time callback method\n
  23. Passing a defined callback method\n
  24. Want to know more\n\nMozilla Developer Network\nHTML5 Spec\nMy Fancy-box fork on github\n
  25. Want to know more\n\nMozilla Developer Network\nHTML5 Spec\nMy Fancy-box fork on github\n