SlideShare a Scribd company logo
introducing OO
 Learning Javascript foundations


           John Hunter
         19 October 2008
what’s OO?
   Object-oriented programming
 (OOP) is a programming paradigm
that uses objects and their interactions
        to design applications
                                 source: wikipedia/Object Orientated
review
types
                   type             examples
                  String         ' Apples' quot;42quot;
primitive type




                 Number           42 3.12 -9
                 Boolean           true false
                 Object         { x: 100, y: 200 }
reference type




                  Array        [' Apples', 42, 3.12]
                 Function       function () { ... }
functions are like other types - we can
       assign them to variables

 function showMessage (msg) {
                                       declare a named function
    console.log(msg);
 }

 var showMessage = function (msg) {
                                      declare a variable and assign it
    console.log(msg);
                                         an anonymous function
 }
function showMessage (msg) {
   console.log(msg);
}

showMessage('Goodbye');

                                 create a reference to the
var showAnother = showMessage;
                                     original function
showAnother('Hello');


Goodbye
Hello
showMessage         Function




showAnother
                      call the
                       same
                     function



              showAnother('Hello');
              showMessage('Goodbye');
...now for something
 completely different
by Roadsidepictures           http://www.techlib.com/electronics/crystal.html




                      good   bad
Object-oriented programming may be seen as a
collection of cooperating objects, as opposed to a
traditional view in which a program may be seen
 as a group of tasks to compute (quot;subroutinesquot;).


Each object can be viewed as an independent little
   machine with a distinct role or responsibility.

                                         source: wikipedia/Object Orientated
radio
      1.
           volume
           frequency

           changeVolume ()
      2.
           changeTuner ()




1. properties - hold the state of an object
2. methods - provide the object with behaviour
...to the code:
the object module
var radio = {};




                  create an object literal
var radio = {

 volume: 0,

 frequency: 88.0
};




   add properties which will store the object state
var radio = {

 volume: 0,

 frequency: 88.0,


 changeVolume: function (direction) {},

 changeTuner: function (direction) {}
};




  add methods which will give the object behaviour
var radio = {
 
 volume: 0,
 
    frequency: 88.0,
 
 
    changeVolume: function (direction) {
 
    
 if (direction === 'up') this.volume += 1;
 
    
 else this.volume -= 1;
 
    },
 
    changeTuner: function (direction) {
 
      
 if (direction === 'up') this.frequency += 4;
 
    
   else this.frequency -= 4;
 
    }
 };
code the functionality that gives methods their behaviour
adjust the volume...


radio.changeVolume('up'); // volume is 1
radio.changeVolume('up'); // volume is 2
radio.changeVolume('up'); // volume is 3
radio.changeVolume('down'); // volume is 2
tune in...

radio. changeTuner('up'); // frequency is 92.0 Mhz
radio. changeTuner('up'); // frequency is 96.0 Mhz
radio. changeTuner('up'); // frequency is 100.0 Mhz
radio. changeTuner('up'); // frequency is 104.0 Mhz
radio. changeTuner('up'); // frequency is 108.0 Mhz
radio. changeTuner('down'); // frequency is 104.0 Mhz
radio
 volume
 frequency

 changeVolume ()
 changeTuner ()




models the real world object
encapsulates code in a single object
lets see some
  real code!
Review
functions, like objects, are a data type
OO approach:
  - objects have roles and interact
  - objects model the real world and are self-contained
object module:
  - an object literal containing properies and functions
  - allows you to structure code on object-oriented principles
homework!
           r own
       you
Build
            radio
     sistor
tran                    ome
                      s
                         arts
                       p
                            ed!!
                       clud
                    in
Thanks

More Related Content

What's hot

Oop07 6
Oop07 6Oop07 6
Oop07 6
schwaa
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
Phúc Đỗ
 
Advanced data structures using c++ 3
Advanced data structures using c++ 3Advanced data structures using c++ 3
Advanced data structures using c++ 3
Shaili Choudhary
 

What's hot (20)

Oop07 6
Oop07 6Oop07 6
Oop07 6
 
CLASSES, STRUCTURE,UNION in C++
CLASSES, STRUCTURE,UNION in C++CLASSES, STRUCTURE,UNION in C++
CLASSES, STRUCTURE,UNION in C++
 
OO in JavaScript
OO in JavaScriptOO in JavaScript
OO in JavaScript
 
ActionScript3 collection query API proposal
ActionScript3 collection query API proposalActionScript3 collection query API proposal
ActionScript3 collection query API proposal
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 
Farhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd YearFarhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd Year
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
 
iOS Session-2
iOS Session-2iOS Session-2
iOS Session-2
 
Built in classes in java
Built in classes in javaBuilt in classes in java
Built in classes in java
 
01 objective-c session 1
01  objective-c session 101  objective-c session 1
01 objective-c session 1
 
Introduction to c ++ part -2
Introduction to c ++   part -2Introduction to c ++   part -2
Introduction to c ++ part -2
 
JAVA CONCEPTS
JAVA CONCEPTS JAVA CONCEPTS
JAVA CONCEPTS
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
 
Advanced data structures using c++ 3
Advanced data structures using c++ 3Advanced data structures using c++ 3
Advanced data structures using c++ 3
 
Lsl scripts
Lsl scriptsLsl scripts
Lsl scripts
 
Autoboxing And Unboxing In Java
Autoboxing And Unboxing In JavaAutoboxing And Unboxing In Java
Autoboxing And Unboxing In Java
 
JVM and OOPS Introduction
JVM and OOPS IntroductionJVM and OOPS Introduction
JVM and OOPS Introduction
 
JSpiders - Wrapper classes
JSpiders - Wrapper classesJSpiders - Wrapper classes
JSpiders - Wrapper classes
 

Similar to Javascript foundations: Introducing OO

javascript
javascript javascript
javascript
Kaya Ota
 
Eqela Core API and Utilities
Eqela Core API and UtilitiesEqela Core API and Utilities
Eqela Core API and Utilities
jobandesther
 

Similar to Javascript foundations: Introducing OO (20)

Class & Object - Intro
Class & Object - IntroClass & Object - Intro
Class & Object - Intro
 
JavsScript OOP
JavsScript OOPJavsScript OOP
JavsScript OOP
 
Cocoa Design Patterns in Swift
Cocoa Design Patterns in SwiftCocoa Design Patterns in Swift
Cocoa Design Patterns in Swift
 
K is for Kotlin
K is for KotlinK is for Kotlin
K is for Kotlin
 
Oop java
Oop javaOop java
Oop java
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & Answers
 
#pugMi - DDD - Value objects
#pugMi - DDD - Value objects#pugMi - DDD - Value objects
#pugMi - DDD - Value objects
 
javascript
javascript javascript
javascript
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
Classes1
Classes1Classes1
Classes1
 
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
 
Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications  Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications
 
6976.ppt
6976.ppt6976.ppt
6976.ppt
 
Eqela Core API and Utilities
Eqela Core API and UtilitiesEqela Core API and Utilities
Eqela Core API and Utilities
 
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1
 
JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
 

Recently uploaded

Recently uploaded (20)

Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Transforming The New York Times: Empowering Evolution through UX
Transforming The New York Times: Empowering Evolution through UXTransforming The New York Times: Empowering Evolution through UX
Transforming The New York Times: Empowering Evolution through UX
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Motion for AI: Creating Empathy in Technology
Motion for AI: Creating Empathy in TechnologyMotion for AI: Creating Empathy in Technology
Motion for AI: Creating Empathy in Technology
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
Intelligent Gimbal FINAL PAPER Engineering.pdf
Intelligent Gimbal FINAL PAPER Engineering.pdfIntelligent Gimbal FINAL PAPER Engineering.pdf
Intelligent Gimbal FINAL PAPER Engineering.pdf
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 

Javascript foundations: Introducing OO

  • 1. introducing OO Learning Javascript foundations John Hunter 19 October 2008
  • 2. what’s OO? Object-oriented programming (OOP) is a programming paradigm that uses objects and their interactions to design applications source: wikipedia/Object Orientated
  • 4. types type examples String ' Apples' quot;42quot; primitive type Number 42 3.12 -9 Boolean true false Object { x: 100, y: 200 } reference type Array [' Apples', 42, 3.12] Function function () { ... }
  • 5. functions are like other types - we can assign them to variables function showMessage (msg) { declare a named function console.log(msg); } var showMessage = function (msg) { declare a variable and assign it console.log(msg); an anonymous function }
  • 6. function showMessage (msg) { console.log(msg); } showMessage('Goodbye'); create a reference to the var showAnother = showMessage; original function showAnother('Hello'); Goodbye Hello
  • 7. showMessage Function showAnother call the same function showAnother('Hello'); showMessage('Goodbye');
  • 8. ...now for something completely different
  • 9. by Roadsidepictures http://www.techlib.com/electronics/crystal.html good bad
  • 10. Object-oriented programming may be seen as a collection of cooperating objects, as opposed to a traditional view in which a program may be seen as a group of tasks to compute (quot;subroutinesquot;). Each object can be viewed as an independent little machine with a distinct role or responsibility. source: wikipedia/Object Orientated
  • 11. radio 1. volume frequency changeVolume () 2. changeTuner () 1. properties - hold the state of an object 2. methods - provide the object with behaviour
  • 12. ...to the code: the object module
  • 13. var radio = {}; create an object literal
  • 14. var radio = { volume: 0, frequency: 88.0 }; add properties which will store the object state
  • 15. var radio = { volume: 0, frequency: 88.0, changeVolume: function (direction) {}, changeTuner: function (direction) {} }; add methods which will give the object behaviour
  • 16. var radio = { volume: 0, frequency: 88.0, changeVolume: function (direction) { if (direction === 'up') this.volume += 1; else this.volume -= 1; }, changeTuner: function (direction) { if (direction === 'up') this.frequency += 4; else this.frequency -= 4; } }; code the functionality that gives methods their behaviour
  • 17. adjust the volume... radio.changeVolume('up'); // volume is 1 radio.changeVolume('up'); // volume is 2 radio.changeVolume('up'); // volume is 3 radio.changeVolume('down'); // volume is 2
  • 18. tune in... radio. changeTuner('up'); // frequency is 92.0 Mhz radio. changeTuner('up'); // frequency is 96.0 Mhz radio. changeTuner('up'); // frequency is 100.0 Mhz radio. changeTuner('up'); // frequency is 104.0 Mhz radio. changeTuner('up'); // frequency is 108.0 Mhz radio. changeTuner('down'); // frequency is 104.0 Mhz
  • 19. radio volume frequency changeVolume () changeTuner () models the real world object encapsulates code in a single object
  • 20. lets see some real code!
  • 21. Review functions, like objects, are a data type OO approach: - objects have roles and interact - objects model the real world and are self-contained object module: - an object literal containing properies and functions - allows you to structure code on object-oriented principles
  • 22. homework! r own you Build radio sistor tran ome s arts p ed!! clud in