SlideShare a Scribd company logo
Object-Oriented Programming

With JavaScript
• Object-oriented programming (OOP)
uses “objects”– data structures consisting
of datafields and methods and their
interactions to design applications and
computer programs
• Each object can be seen as a tiny machine
which is responsible for the set of task assign
to it.
• Today, many popular programming languages
(such as Java, JavaScript, C#, C++, Python, PHP
etc) support object-oriented
programming (OOP).
• JavaScript has strong object-oriented
programming capabilities. Although there is
differences in object-oriented capability of
javascript compared to other languages.
Terminology
• Class: Defines the characteristics of the
Object.
Constructor: A method called at the moment
of instantiation.
Object: An Instance of a Class.
Method: An Object capability as walk.
Property: An Object characteristic, such as
color.
Inheritance: A Class can inherit characteristics
from another Class.
• Encapsulation: A Class defines only the
characteristics of the Object, a method
defines only how the method executes.
Abstraction: The conjunction of complex
inheritance, methods, properties of an Object
must be able to simulate a reality model.
Polymorphism: Different Classes might define
the same method or property.
Object oriented programming
The Class in JavaScript
• Unlike Java, C++ etc., JavaScript does not
contains class statement. JavaScript is a
prototype-based language. JavaScript uses
functions as classes. Defining a class is as easy
as defining a function. In the example below
we define a new class called Car.
The Object
(Class Instance) in JavaScript
• For creating instances of any class i.e. objects
use new keyword. For example, in below code
snippet we created two instances of class Car.
Constructor
• Constructor is a method that is used to initiate
the properties of any class instance.
• Thus the constructor gets called when the
class is instantiated.
• As in JavaScript there is no class keyword and
the function serves as class definition, there is
no need of defining constructor explicitly. The
function defined for the class acts as
constructor.
• For example, in following code snippet we
have called an alert statement when class Car
is instantiated.
Property
(Class Instance) in JavaScript
• Properties are the variable that are member
of an object and can define the state of any
instance of Class. Property of a class can be
accessed within the class using this keyword.
For example, in following code snippet we
have assign a property speed to Car.
Object oriented programming
• One thing we should note here is that for
inheritance works correctly, the Properties
should be set in the prototype property of the
class (function). The above example becomes:
Object oriented programming
Methods
• To define methods in a Class, all you have to
do is just define a attribute and assign an
function to it. For example, in below code
snippet we defined a method setSpeed() for
class Car.
Object oriented programming
Inheritance in JavaScript
• JavaScript supports single class inheritance. To
create a child class that inherit parent
class, we create a Parent class object and
assign it to the Child class. In following
example we created a child class Ferrari from
parent class Car.
Object oriented programming

More Related Content

PPTX
[OOP - Lec 04,05] Basic Building Blocks of OOP
PDF
Akka actorstotherescue nirmalya sengupta
PPTX
[OOP - Lec 01] Introduction to OOP
PPT
Basic concepts of oops
PPTX
Basics of Object Oriented Programming
PPTX
[OOP - Lec 18] Static Data Member
PDF
Flutter Dev 2019
PPT
04 inheritance
[OOP - Lec 04,05] Basic Building Blocks of OOP
Akka actorstotherescue nirmalya sengupta
[OOP - Lec 01] Introduction to OOP
Basic concepts of oops
Basics of Object Oriented Programming
[OOP - Lec 18] Static Data Member
Flutter Dev 2019
04 inheritance

What's hot (20)

PPSX
Class as the basis of all computation
PPTX
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
PPTX
2CPP04 - Objects and Classes
PPTX
Object Oriented Programming Principles
PDF
Java Training | Online Java Training
PDF
Metaprogramming ruby
PPTX
Introduction to JavaScript
PPTX
Function-and-prototype defined classes in JavaScript
PPSX
Arrays in Java
PPT
power poitnt of oops
PPTX
Session 04 - Arrays in Java
PPTX
Inheritance in JAVA PPT
PPTX
Introducing classes
PPTX
Java object oriented programming concepts - Brainsmartlabs
PDF
05 ruby classes
PPTX
Object oriented programming
PPTX
Principles and advantages of oop ppt
PPTX
Polymorphism
PPTX
Packages
PDF
Concepts of OOPs
Class as the basis of all computation
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
2CPP04 - Objects and Classes
Object Oriented Programming Principles
Java Training | Online Java Training
Metaprogramming ruby
Introduction to JavaScript
Function-and-prototype defined classes in JavaScript
Arrays in Java
power poitnt of oops
Session 04 - Arrays in Java
Inheritance in JAVA PPT
Introducing classes
Java object oriented programming concepts - Brainsmartlabs
05 ruby classes
Object oriented programming
Principles and advantages of oop ppt
Polymorphism
Packages
Concepts of OOPs
Ad

Viewers also liked (8)

PPT
Jewelry,Cagas, Bermarin (LQR1)
PPT
LOGOTERAPIA
PPTX
ฉันเหมือนใคร9
PPTX
Sloodle(68703 & 82915)
PPTX
Presentation1
PPT
Power point งานสุขศึกษา 2
PPT
Tech4101 1 (68703& 82915)
PPT
Tech4101 1 (68703& 82915)
Jewelry,Cagas, Bermarin (LQR1)
LOGOTERAPIA
ฉันเหมือนใคร9
Sloodle(68703 & 82915)
Presentation1
Power point งานสุขศึกษา 2
Tech4101 1 (68703& 82915)
Tech4101 1 (68703& 82915)
Ad

Similar to Object oriented programming (20)

PPTX
Advance Javascript for Coders
PPTX
Object oriented javascript
PPTX
unit-2 part-1.pptx
PPTX
Understanding-Objects-in-Javascript.pptx
PPTX
pert.3&4.pptx
PPTX
Object Oriented Programming In JavaScript
PPTX
13_User_Defined_Objects.pptx objects in javascript
PPTX
Object Oriented Javascript part2
PPTX
Jscript part2
PPTX
JavaScript OOPS Implimentation
PDF
JavaScript - Chapter 8 - Objects
PDF
OOPS JavaScript Interview Questions PDF By ScholarHat
PPTX
Object oriented programming in JavaScript
PPT
Java script unleashed
PPTX
IWT presentation121232112122222225556+556.pptx
PPTX
JavaScript in Object-Oriented Way
PPTX
OO in JavaScript
PPTX
Cordova training : Day 4 - Advanced Javascript
PPTX
Javascriptinobject orientedway-090512225827-phpapp02
PPTX
Object oriented javascript
Advance Javascript for Coders
Object oriented javascript
unit-2 part-1.pptx
Understanding-Objects-in-Javascript.pptx
pert.3&4.pptx
Object Oriented Programming In JavaScript
13_User_Defined_Objects.pptx objects in javascript
Object Oriented Javascript part2
Jscript part2
JavaScript OOPS Implimentation
JavaScript - Chapter 8 - Objects
OOPS JavaScript Interview Questions PDF By ScholarHat
Object oriented programming in JavaScript
Java script unleashed
IWT presentation121232112122222225556+556.pptx
JavaScript in Object-Oriented Way
OO in JavaScript
Cordova training : Day 4 - Advanced Javascript
Javascriptinobject orientedway-090512225827-phpapp02
Object oriented javascript

Recently uploaded (20)

PDF
advance database management system book.pdf
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PDF
IGGE1 Understanding the Self1234567891011
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
Hazard Identification & Risk Assessment .pdf
PPTX
Introduction to pro and eukaryotes and differences.pptx
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Introduction to Building Materials
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
My India Quiz Book_20210205121199924.pdf
PPTX
TNA_Presentation-1-Final(SAVE)) (1).pptx
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Trump Administration's workforce development strategy
advance database management system book.pdf
Share_Module_2_Power_conflict_and_negotiation.pptx
IGGE1 Understanding the Self1234567891011
AI-driven educational solutions for real-life interventions in the Philippine...
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
Hazard Identification & Risk Assessment .pdf
Introduction to pro and eukaryotes and differences.pptx
A powerpoint presentation on the Revised K-10 Science Shaping Paper
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Introduction to Building Materials
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Unit 4 Computer Architecture Multicore Processor.pptx
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
My India Quiz Book_20210205121199924.pdf
TNA_Presentation-1-Final(SAVE)) (1).pptx
What if we spent less time fighting change, and more time building what’s rig...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Trump Administration's workforce development strategy

Object oriented programming

  • 2. • Object-oriented programming (OOP) uses “objects”– data structures consisting of datafields and methods and their interactions to design applications and computer programs • Each object can be seen as a tiny machine which is responsible for the set of task assign to it.
  • 3. • Today, many popular programming languages (such as Java, JavaScript, C#, C++, Python, PHP etc) support object-oriented programming (OOP). • JavaScript has strong object-oriented programming capabilities. Although there is differences in object-oriented capability of javascript compared to other languages.
  • 5. • Class: Defines the characteristics of the Object. Constructor: A method called at the moment of instantiation. Object: An Instance of a Class. Method: An Object capability as walk. Property: An Object characteristic, such as color. Inheritance: A Class can inherit characteristics from another Class.
  • 6. • Encapsulation: A Class defines only the characteristics of the Object, a method defines only how the method executes. Abstraction: The conjunction of complex inheritance, methods, properties of an Object must be able to simulate a reality model. Polymorphism: Different Classes might define the same method or property.
  • 8. The Class in JavaScript • Unlike Java, C++ etc., JavaScript does not contains class statement. JavaScript is a prototype-based language. JavaScript uses functions as classes. Defining a class is as easy as defining a function. In the example below we define a new class called Car.
  • 9. The Object (Class Instance) in JavaScript • For creating instances of any class i.e. objects use new keyword. For example, in below code snippet we created two instances of class Car.
  • 10. Constructor • Constructor is a method that is used to initiate the properties of any class instance. • Thus the constructor gets called when the class is instantiated. • As in JavaScript there is no class keyword and the function serves as class definition, there is no need of defining constructor explicitly. The function defined for the class acts as constructor.
  • 11. • For example, in following code snippet we have called an alert statement when class Car is instantiated.
  • 12. Property (Class Instance) in JavaScript • Properties are the variable that are member of an object and can define the state of any instance of Class. Property of a class can be accessed within the class using this keyword. For example, in following code snippet we have assign a property speed to Car.
  • 14. • One thing we should note here is that for inheritance works correctly, the Properties should be set in the prototype property of the class (function). The above example becomes:
  • 16. Methods • To define methods in a Class, all you have to do is just define a attribute and assign an function to it. For example, in below code snippet we defined a method setSpeed() for class Car.
  • 18. Inheritance in JavaScript • JavaScript supports single class inheritance. To create a child class that inherit parent class, we create a Parent class object and assign it to the Child class. In following example we created a child class Ferrari from parent class Car.