java scrip to op

Upload: duahaudo

Post on 06-Apr-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/2/2019 Java Scrip to Op

    1/23

    Object Oriented Programming

    in JavaScript

    PhuongH

  • 8/2/2019 Java Scrip to Op

    2/23

    Introduction Introduction about using Object

    Oriented in JavaScript programming.

    Knowledge requirements:

    Object Oriented Programming.

    JavaScript

  • 8/2/2019 Java Scrip to Op

    3/23

    Content

    Working with object in JavaScript.

    Object Oriented Programing goals. OOP in JavaScript.

    Summary.

  • 8/2/2019 Java Scrip to Op

    4/23

    Content

    Working with object in JavaScript.

    Object Oriented Programing goals. OOP in JavaScript.

    Summary.

  • 8/2/2019 Java Scrip to Op

    5/23

    Working with object

    in JavaScript Built-in object type in JavaScript.

    There are several ways to create anobject in JavaScript.

    Example 3

    Example 1 Example 2

  • 8/2/2019 Java Scrip to Op

    6/23

    Content

    Working with object in JavaScript.

    Object Oriented Programing goals. OOP in JavaScript.

    Summary.

  • 8/2/2019 Java Scrip to Op

    7/23

    Object Oriented Programing

    goalsAbstract.

    Encapsulation. Inheritance.

    Polymorphism.

  • 8/2/2019 Java Scrip to Op

    8/23

    Content

    Working with object in JavaScript.

    Object Oriented Programing goals. OOP in JavaScript.

    Summary.

  • 8/2/2019 Java Scrip to Op

    9/23

    OOP in JavaScript

    JavaScriptIS NOT a Object Orientedlanguage like C++,C#, Java,

    Using JavaScripts characters to obtain theOOP goals.

  • 8/2/2019 Java Scrip to Op

    10/23

    OOP in JavaScript - Content

    Class and access modifiers

    Inheritance & Polymorphism

  • 8/2/2019 Java Scrip to Op

    11/23

    OOP in JavaScript - Content

    Class and access modifiers

    Inheritance & Polymorphism

  • 8/2/2019 Java Scrip to Op

    12/23

    OOP in JavaScript

    Defining class Using function declaration to define a class.

    Example: define a simple class Student

  • 8/2/2019 Java Scrip to Op

    13/23

    OOP in JavaScript

    Access modifiers & Accessor

    JavaScript does not have a reserve word formaking a variable private, JavaScript gives

    us the tools to create the same effect Define functions get and set to work as

    accessor.

  • 8/2/2019 Java Scrip to Op

    14/23

    OOP in JavaScript

    Access modifiers & Accessor(cont.)

  • 8/2/2019 Java Scrip to Op

    15/23

    OOP in

    JavaScriptDynamicallyGenerated

    Accessor

  • 8/2/2019 Java Scrip to Op

    16/23

    OOP in JavaScript

    Dynamically Generated Accessor

    Not only do we keep our propertiesprivate, we avoid the need to specifyour arguments in order.

    The following class instantiations are allequivalent

  • 8/2/2019 Java Scrip to Op

    17/23

    OOP in JavaScript - Content

    Class and access modifiers

    Inheritance & Polymorphism

  • 8/2/2019 Java Scrip to Op

    18/23

    OOP in JavaScript

    Inheritance & Polymorphism Using JavaScritpt prototype object,

    introduced starting in JavaScript 1.1, isa prebuilt object that simplifies theprocess of adding custom properties/methods to all instances of an object.

    Examples

  • 8/2/2019 Java Scrip to Op

    19/23

    OOP in JavaScript

    Inheritance & Polymorphism(cont.)

    Situation: we have 2 types of workers:wage-based and commission-based.

    Each worker will have name, base onthe type, it will have some additionproperties.

    The worker have method to calculate itsincome but in the different way base onits type.

  • 8/2/2019 Java Scrip to Op

    20/23

    OOP in JavaScript

    Inheritance & Polymorphism(cont.)

    In this example, we will create a super-class called Worker and 2 sub-class:CommissionWorker and WageWorker.

    This example will illustrate for the goalsInheritance and Polymorphism in OOP.

  • 8/2/2019 Java Scrip to Op

    21/23

    Content

    Working with object in JavaScript.

    Object Oriented Programing goals. OOP in JavaScript.

    Summary.

  • 8/2/2019 Java Scrip to Op

    22/23

    Summary

    JavaScriptIS NOT a Object Orientedlanguage like C++,C#, Java,

    The OOP goals is obtained by usingsome special JavaScripts characters.

    JavaScript OOP obtain both 4

    important goals of OOP.

  • 8/2/2019 Java Scrip to Op

    23/23

    More information

    www.google.com :D

    www.w3schools.com www.webreference.com