SlideShare a Scribd company logo
Understanding Object Oriented Javascript - Coffee@DBG June
 JavaScript Object.
 JavaScript Functions.
 Self-invoking function.
 JavaScript Prototype.
 Advanced JavaScript.
Understanding Object Oriented Javascript - Coffee@DBG June
 What is it ?
 JavaScript objects are dynamic.
 You can add a new property at runtime just by assigning it.
 No need to declare data types.
Continued…
Object
Native Objects Host Objects User Defined
Objects
1. String
2. Number
3. Array
4. Date
5. ……
1. Window
2. Document
3. Forms
4. ……
Defined by
Programmer
 There are three object categories in JavaScript.
Ex: var today = new Date();
var name = new String(“DBG”)
Ex: document.getElementById()
 Two common ways to create objects.
Continued…
JavaScript
Objects
Object Literal
Object
Constructor
• An object literal is a comma-separated list of
name-value pairs wrapped in curly braces.
• When a function is called with the ”new” operator,
the function serves as the constructor .
• Internally, JavaScript creates an Object, and then
calls the constructor function.
 Object Literal Vs Object Constructor
Object Literal Object Constructor
Properties and methods are always public. Properties and methods can be private/public.
When a change is made to an Object Literal it
affects that object across the entire script
When a Constructor function is instantiated
and then a change is made to that instance, it
won't affect any other instances of that
object.
function Mobile(){
this.model = "Galaxy Nexus";
this.type = "Android";
this.IMEI = "234034958";
};
var phone = new Mobile();
var phone = {
model: “Galaxy Nexus”,
type: “Android”,
IMEI: “234034958”
};
Understanding Object Oriented Javascript - Coffee@DBG June
 functions are objects.
 functions have properties and methods.
 function can be stored in a variable.
 function serves as the constructor of the object; therefore, there is no need to explicitly define a
constructor method.
Continued…
function mobile(){
// your code….
}
 Type of functions :
Continued…
JavaScript
Functions
Named
Functions
Anonymous
Functions
Named Functions (function declaration) Anonymous functions(function operator)
function makeCall(){
alert(“ To make call”);
}
var makeCall= function(){
alert(“ To make call”);
}
Function Declaration
Function Name
Function Body
variable that stores
returned object
Function Operator
Function Body
Named Functions (function declaration) Anonymous functions(function operator)
function makeCall(){
alert(“ To make call”);
}
var makeCall= function(){
alert(“ To make call”);
}
Function Declaration
Function Name
Function Body
variable that stores
returned object
Function Operator
Function Body
 function declarations vs function operators
Named Functions Anonymous Functions
Named functions are created using the
“function declaration”.
Anonymous functions are created using the
“function operator”.
This function object will be created as the
JavaScript is parsed, before the code is run.
Anonymous functions are created at
runtime.
It can be called before the function
statement declaration.
Anonymous functions don’t have a name
Understanding Object Oriented Javascript - Coffee@DBG June
 Self-invoking function means function which invokes itself .
 After the function have been initialized it’s immediately invoked.
 We don’t keep reference to that function, not even to it’s return value.
(function(){
// function body
}();
Understanding Object Oriented Javascript - Coffee@DBG June
 “Prototype” is a property belonging only to functions.
 The “prototype” allow you to easily define methods to all instances of a particular object.
 Those type of methods is only stored in the memory once, but every instance of the object
can access it.
Continued…
Mobile
default constructor
model & type private
variable
sendSMS() – privileged function
makeCall – using “prototype”
property to create makeCall
function
Mobile.prototype.makeCall =
function(){}
Objects
var phone1 = new Mobile()
var phone2 = new Mobile()
var phone3 = new Mobile()
stored in memory once .
creating separate
functions for each
object.
 The “constructor” property.
 An object has a built-in property named ”constructor”. It is a reference to the function that
created an object.
Continued…
function Mobile () {
/* your code */
}
{
constructor : Mobile
}
Prototype
Autocreated with function
• When “new Mobile()” is called, the “Mobile.prototype” becomes __proto__ and the
constructor becomes accessible from the object.
• The interpreter creates the new function from the declaration(Together with the function,
and its prototype) .
 Chrome watch expression view of a function
 hasOwnProperty
 All objects have hasOwnProperty method which allows to check if a property belongs to the
object or its prototype.
mobile
function – makeCall hasOwnProperty (‘makeCall’)
True
Continued…
Created an object “Phone”
var phone = new Mobile()
 JavaScript OOPs.
Continued…
Class Defines the characteristics of the Object
Object An Instance of a Class.
Property An Object characteristic, such as “IMEI”.
Methods Object capability, such as “makeCall”.
Constructor A method called at the moment of instantiation.
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.
Polymorphism Different Classes might define the same method or property.
Understanding Object Oriented Javascript - Coffee@DBG June
 Class
 In JavaScript, “class” can be created by a function.
 When “new” operator is used, a function serves as a constructor for that class.
 Internally, JavaScript creates an “Object”, and then calls the constructor function.
Class
1. default constructor.
2. local & member variable.
3. public/private functions.
Mobile – Sample Class
1. default constructor.
2. Properties, lets say
(a) IMEI
(b) type
(c) model
3. makeCall & sendSMS are the public
functions.
 Public/Private and Privileged functions
 Private function - A function which can be accessed ONLY inside a class.
var functionName = function(){
/* your code */
})
 Public function – A function which is created by “prototype” property, which cannot access any
private functions or variables.
className.prototype.functionName = function(){
/* your code */
})
this.functionName = function(){
/* your code */
})
 Privileged function – A function which is created inside a class using “this” keyword. It can
access private variables and functions.
 Object, Property, Method & Constructor
Mobile – Sample Class
1. default constructor
2. Properties, lets say
(a) model – private variable
(b) IMEI – public variable
(c) type – private variable.
3. makeCall & sendSMS are the common
functionality of any mobile – public functions
Phone (An instance of mobile class)
1. default constructor
2. (a) type & model – Variable cannot be
accessed from outside.
(b) IMEI – This is a “Property” of mobile
class
3. makeCall & sendSMS are the “methods” of
the mobile class.
“new” keyword is using to
initializing mobile class object
Object
 Inheritance (Prototype-based Inheritance)
 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.
Mobile (Super Class)
1. default constructor
2. model – Member variable
3. makeCall & sendSMS – public
function
// Super Class
function Mobile(){
/* your code */
}
function Android(){
/* your code*/
}
// inheriting all properties of Mobile class
Android.prototype = new Mobile();
// updating the constructor.
Android.prototype.constructor = Android;
Android (Child Class)
1. default constructor.
2. Using “prototype” property to
inherit all properties and methods
from Mobile
 Encapsulation
 Date hiding is protecting the data form accessing it outside the scope.
Mobile
1. model – Private
Variable
2. getModel – Public
function which will return
the value of model.
Phone
phone.model
Result: undefined
phone.getModel()
Result: The value which is stored in the
IMEI variable.
 Polymorphism
 The word Polymorphism in OOPs means having more than one form.
Mobile
Function: InstallApp()
FYI: It can install any kind
of app.
Android
Function: InstallApp()
FYI: It can install only
Android apps
Windows
Function: InstallApp()
FYI: It can install only
Window apps.
 How JavaScript objects work ?
 Functions are first class objects in JavaScript. “Really, just like any other variable”
 Function operator and function declaration.
 Special feature Hoisting .
 Self invoking function.
 Object Oriented Programming in JavaScript.
 http://www.crockford.com/
 http://www.doctrina.org/
 http://www.robertnyman.com/
 http://www.javascriptissexy.com/
 http://www.javascript.info
Understanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG June

More Related Content

What's hot (20)

PDF
Object Oriented Programming in JavaScript
zand3rs
 
PDF
Java Script Best Practices
Enrique Juan de Dios
 
PDF
Advanced javascript
Doeun KOCH
 
PDF
Prototype
Aditya Gaur
 
PDF
Core concepts-javascript
Prajwala Manchikatla
 
PDF
JavaScript - From Birth To Closure
Robert Nyman
 
PPTX
Javascript Prototype Visualized
军 沈
 
PDF
JavaScript Patterns
Stoyan Stefanov
 
PDF
JavaScript Basics and Best Practices - CC FE & UX
JWORKS powered by Ordina
 
PPTX
Javascript Objects Deep Dive
Manish Jangir
 
KEY
JavaScript Growing Up
David Padbury
 
PPTX
Javascript Prototypal Inheritance - Big Picture
Manish Jangir
 
PPTX
Javascript basics for automation testing
Vikas Thange
 
PPTX
5 Tips for Better JavaScript
Todd Anglin
 
PPTX
Interesting Facts About Javascript
Manish Jangir
 
PPTX
Object Oriented Programming In JavaScript
Forziatech
 
ODP
Javascript
theacadian
 
PDF
Advanced Object-Oriented JavaScript
ecker
 
PPT
JavaScript Basics
Mats Bryntse
 
PDF
Iphone course 1
Janet Huang
 
Object Oriented Programming in JavaScript
zand3rs
 
Java Script Best Practices
Enrique Juan de Dios
 
Advanced javascript
Doeun KOCH
 
Prototype
Aditya Gaur
 
Core concepts-javascript
Prajwala Manchikatla
 
JavaScript - From Birth To Closure
Robert Nyman
 
Javascript Prototype Visualized
军 沈
 
JavaScript Patterns
Stoyan Stefanov
 
JavaScript Basics and Best Practices - CC FE & UX
JWORKS powered by Ordina
 
Javascript Objects Deep Dive
Manish Jangir
 
JavaScript Growing Up
David Padbury
 
Javascript Prototypal Inheritance - Big Picture
Manish Jangir
 
Javascript basics for automation testing
Vikas Thange
 
5 Tips for Better JavaScript
Todd Anglin
 
Interesting Facts About Javascript
Manish Jangir
 
Object Oriented Programming In JavaScript
Forziatech
 
Javascript
theacadian
 
Advanced Object-Oriented JavaScript
ecker
 
JavaScript Basics
Mats Bryntse
 
Iphone course 1
Janet Huang
 

Similar to Understanding Object Oriented Javascript - Coffee@DBG June (20)

PPTX
Javascriptinobject orientedway-090512225827-phpapp02
Sopheak Sem
 
PDF
Javascript closures
VNG
 
PPT
Javascript Workshop
Assaf Weinberg
 
PPTX
JavaScript OOPS Implimentation
Usman Mehmood
 
PDF
[2015/2016] JavaScript
Ivano Malavolta
 
PPTX
Javascript talk
Suresh Jayanty
 
PPTX
Learn JS concepts by implementing jQuery
Wingify Engineering
 
PPTX
Ajaxworld
deannalagason
 
PDF
Design patterns in javascript
Ayush Sharma
 
PDF
JavaScript Programming
Sehwan Noh
 
PPT
Oop Constructor Destructors Constructor Overloading lecture 2
Abbas Ajmal
 
PPT
Advanced Javascript
Manikanda kumar
 
PPT
Advanced Javascript
relay12
 
PDF
JavaScript
Ivano Malavolta
 
PPTX
JavaScript Beyond jQuery
Bobby Bryant
 
PPTX
Lecture 4- Javascript Function presentation
GomathiUdai
 
PDF
Java Programming - 04 object oriented in java
Danairat Thanabodithammachari
 
PPT
packages and interfaces
madhavi patil
 
PDF
The prototype property
Hernan Mammana
 
ODP
Jquery Plugin
Ravi Mone
 
Javascriptinobject orientedway-090512225827-phpapp02
Sopheak Sem
 
Javascript closures
VNG
 
Javascript Workshop
Assaf Weinberg
 
JavaScript OOPS Implimentation
Usman Mehmood
 
[2015/2016] JavaScript
Ivano Malavolta
 
Javascript talk
Suresh Jayanty
 
Learn JS concepts by implementing jQuery
Wingify Engineering
 
Ajaxworld
deannalagason
 
Design patterns in javascript
Ayush Sharma
 
JavaScript Programming
Sehwan Noh
 
Oop Constructor Destructors Constructor Overloading lecture 2
Abbas Ajmal
 
Advanced Javascript
Manikanda kumar
 
Advanced Javascript
relay12
 
JavaScript
Ivano Malavolta
 
JavaScript Beyond jQuery
Bobby Bryant
 
Lecture 4- Javascript Function presentation
GomathiUdai
 
Java Programming - 04 object oriented in java
Danairat Thanabodithammachari
 
packages and interfaces
madhavi patil
 
The prototype property
Hernan Mammana
 
Jquery Plugin
Ravi Mone
 
Ad

More from Deepu S Nath (20)

PPTX
Design Thinking, Critical Thinking & Innovation Design
Deepu S Nath
 
PDF
GTECH ATFG µLearn Framework Intro
Deepu S Nath
 
PPTX
Future of learning - Technology Disruption
Deepu S Nath
 
PDF
Decentralized Applications using Ethereum
Deepu S Nath
 
PDF
How machines can take decisions
Deepu S Nath
 
PDF
Artificial Intelligence: An Introduction
Deepu S Nath
 
PPTX
FAYA PORT 80 Introduction
Deepu S Nath
 
PDF
How machines can take decisions
Deepu S Nath
 
PDF
Simplified Introduction to AI
Deepu S Nath
 
PPTX
Mining Opportunities of Block Chain and BitCoin
Deepu S Nath
 
PPTX
Introduction to DevOps
Deepu S Nath
 
PPT
Coffee@DBG - TechBites March 2016
Deepu S Nath
 
PPTX
REACT.JS : Rethinking UI Development Using JavaScript
Deepu S Nath
 
PPT
SEO For Developers
Deepu S Nath
 
PDF
Life Cycle of an App - From Idea to Monetization
Deepu S Nath
 
PPT
Uncommon Python - What is special in Python
Deepu S Nath
 
PPT
Coffee@DBG - TechBites Sept 2015
Deepu S Nath
 
PPT
Techbites July 2015
Deepu S Nath
 
PPT
Apple Watch - Start Your Developer Engine
Deepu S Nath
 
PPTX
Greetings & Response - English Communication Training
Deepu S Nath
 
Design Thinking, Critical Thinking & Innovation Design
Deepu S Nath
 
GTECH ATFG µLearn Framework Intro
Deepu S Nath
 
Future of learning - Technology Disruption
Deepu S Nath
 
Decentralized Applications using Ethereum
Deepu S Nath
 
How machines can take decisions
Deepu S Nath
 
Artificial Intelligence: An Introduction
Deepu S Nath
 
FAYA PORT 80 Introduction
Deepu S Nath
 
How machines can take decisions
Deepu S Nath
 
Simplified Introduction to AI
Deepu S Nath
 
Mining Opportunities of Block Chain and BitCoin
Deepu S Nath
 
Introduction to DevOps
Deepu S Nath
 
Coffee@DBG - TechBites March 2016
Deepu S Nath
 
REACT.JS : Rethinking UI Development Using JavaScript
Deepu S Nath
 
SEO For Developers
Deepu S Nath
 
Life Cycle of an App - From Idea to Monetization
Deepu S Nath
 
Uncommon Python - What is special in Python
Deepu S Nath
 
Coffee@DBG - TechBites Sept 2015
Deepu S Nath
 
Techbites July 2015
Deepu S Nath
 
Apple Watch - Start Your Developer Engine
Deepu S Nath
 
Greetings & Response - English Communication Training
Deepu S Nath
 
Ad

Recently uploaded (20)

PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Digital Circuits, important subject in CS
contactparinay1
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 

Understanding Object Oriented Javascript - Coffee@DBG June

  • 2.  JavaScript Object.  JavaScript Functions.  Self-invoking function.  JavaScript Prototype.  Advanced JavaScript.
  • 4.  What is it ?  JavaScript objects are dynamic.  You can add a new property at runtime just by assigning it.  No need to declare data types. Continued… Object Native Objects Host Objects User Defined Objects 1. String 2. Number 3. Array 4. Date 5. …… 1. Window 2. Document 3. Forms 4. …… Defined by Programmer  There are three object categories in JavaScript. Ex: var today = new Date(); var name = new String(“DBG”) Ex: document.getElementById()
  • 5.  Two common ways to create objects. Continued… JavaScript Objects Object Literal Object Constructor • An object literal is a comma-separated list of name-value pairs wrapped in curly braces. • When a function is called with the ”new” operator, the function serves as the constructor . • Internally, JavaScript creates an Object, and then calls the constructor function.
  • 6.  Object Literal Vs Object Constructor Object Literal Object Constructor Properties and methods are always public. Properties and methods can be private/public. When a change is made to an Object Literal it affects that object across the entire script When a Constructor function is instantiated and then a change is made to that instance, it won't affect any other instances of that object. function Mobile(){ this.model = "Galaxy Nexus"; this.type = "Android"; this.IMEI = "234034958"; }; var phone = new Mobile(); var phone = { model: “Galaxy Nexus”, type: “Android”, IMEI: “234034958” };
  • 8.  functions are objects.  functions have properties and methods.  function can be stored in a variable.  function serves as the constructor of the object; therefore, there is no need to explicitly define a constructor method. Continued… function mobile(){ // your code…. }
  • 9.  Type of functions : Continued… JavaScript Functions Named Functions Anonymous Functions Named Functions (function declaration) Anonymous functions(function operator) function makeCall(){ alert(“ To make call”); } var makeCall= function(){ alert(“ To make call”); } Function Declaration Function Name Function Body variable that stores returned object Function Operator Function Body
  • 10. Named Functions (function declaration) Anonymous functions(function operator) function makeCall(){ alert(“ To make call”); } var makeCall= function(){ alert(“ To make call”); } Function Declaration Function Name Function Body variable that stores returned object Function Operator Function Body  function declarations vs function operators Named Functions Anonymous Functions Named functions are created using the “function declaration”. Anonymous functions are created using the “function operator”. This function object will be created as the JavaScript is parsed, before the code is run. Anonymous functions are created at runtime. It can be called before the function statement declaration. Anonymous functions don’t have a name
  • 12.  Self-invoking function means function which invokes itself .  After the function have been initialized it’s immediately invoked.  We don’t keep reference to that function, not even to it’s return value. (function(){ // function body }();
  • 14.  “Prototype” is a property belonging only to functions.  The “prototype” allow you to easily define methods to all instances of a particular object.  Those type of methods is only stored in the memory once, but every instance of the object can access it. Continued… Mobile default constructor model & type private variable sendSMS() – privileged function makeCall – using “prototype” property to create makeCall function Mobile.prototype.makeCall = function(){} Objects var phone1 = new Mobile() var phone2 = new Mobile() var phone3 = new Mobile() stored in memory once . creating separate functions for each object.
  • 15.  The “constructor” property.  An object has a built-in property named ”constructor”. It is a reference to the function that created an object. Continued… function Mobile () { /* your code */ } { constructor : Mobile } Prototype Autocreated with function • When “new Mobile()” is called, the “Mobile.prototype” becomes __proto__ and the constructor becomes accessible from the object. • The interpreter creates the new function from the declaration(Together with the function, and its prototype) .
  • 16.  Chrome watch expression view of a function  hasOwnProperty  All objects have hasOwnProperty method which allows to check if a property belongs to the object or its prototype. mobile function – makeCall hasOwnProperty (‘makeCall’) True Continued… Created an object “Phone” var phone = new Mobile()
  • 17.  JavaScript OOPs. Continued… Class Defines the characteristics of the Object Object An Instance of a Class. Property An Object characteristic, such as “IMEI”. Methods Object capability, such as “makeCall”. Constructor A method called at the moment of instantiation. 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. Polymorphism Different Classes might define the same method or property.
  • 19.  Class  In JavaScript, “class” can be created by a function.  When “new” operator is used, a function serves as a constructor for that class.  Internally, JavaScript creates an “Object”, and then calls the constructor function. Class 1. default constructor. 2. local & member variable. 3. public/private functions. Mobile – Sample Class 1. default constructor. 2. Properties, lets say (a) IMEI (b) type (c) model 3. makeCall & sendSMS are the public functions.
  • 20.  Public/Private and Privileged functions  Private function - A function which can be accessed ONLY inside a class. var functionName = function(){ /* your code */ })  Public function – A function which is created by “prototype” property, which cannot access any private functions or variables. className.prototype.functionName = function(){ /* your code */ }) this.functionName = function(){ /* your code */ })  Privileged function – A function which is created inside a class using “this” keyword. It can access private variables and functions.
  • 21.  Object, Property, Method & Constructor Mobile – Sample Class 1. default constructor 2. Properties, lets say (a) model – private variable (b) IMEI – public variable (c) type – private variable. 3. makeCall & sendSMS are the common functionality of any mobile – public functions Phone (An instance of mobile class) 1. default constructor 2. (a) type & model – Variable cannot be accessed from outside. (b) IMEI – This is a “Property” of mobile class 3. makeCall & sendSMS are the “methods” of the mobile class. “new” keyword is using to initializing mobile class object Object
  • 22.  Inheritance (Prototype-based Inheritance)  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. Mobile (Super Class) 1. default constructor 2. model – Member variable 3. makeCall & sendSMS – public function // Super Class function Mobile(){ /* your code */ } function Android(){ /* your code*/ } // inheriting all properties of Mobile class Android.prototype = new Mobile(); // updating the constructor. Android.prototype.constructor = Android; Android (Child Class) 1. default constructor. 2. Using “prototype” property to inherit all properties and methods from Mobile
  • 23.  Encapsulation  Date hiding is protecting the data form accessing it outside the scope. Mobile 1. model – Private Variable 2. getModel – Public function which will return the value of model. Phone phone.model Result: undefined phone.getModel() Result: The value which is stored in the IMEI variable.  Polymorphism  The word Polymorphism in OOPs means having more than one form. Mobile Function: InstallApp() FYI: It can install any kind of app. Android Function: InstallApp() FYI: It can install only Android apps Windows Function: InstallApp() FYI: It can install only Window apps.
  • 24.  How JavaScript objects work ?  Functions are first class objects in JavaScript. “Really, just like any other variable”  Function operator and function declaration.  Special feature Hoisting .  Self invoking function.  Object Oriented Programming in JavaScript.
  • 25.  http://www.crockford.com/  http://www.doctrina.org/  http://www.robertnyman.com/  http://www.javascriptissexy.com/  http://www.javascript.info