SlideShare a Scribd company logo
Click to add Text 
Javascript 
Presented by Bunlong VAN 
http://geekhmer.github.io 
Object Oriented
The Disclaimer
Object Oriented Basic 
โ€ขObject (instance): representation of a โ€œthingโ€ (someone or 
something) 
โ€ขClass: ablueprint, or recipe for an Object 
โ€ขEncapsulation: illustrates the fact that an Object contains 
(encapsulates): 
โ€ข Data (stored in properties) 
โ€ข The means to do something with data (using 
methods) 
โ€ขInheritance
Object Creation 
โ€ขTwo simple ways 
var obj = new Object(); 
obj.name = โ€œFooโ€; 
obj.say = function() { 
return โ€œHelloโ€; 
} 
var obj = { 
name: โ€œFooโ€, 
say: function() { 
return โ€œHelloโ€; 
} 
}
Method 
โ€ขWhen a property is a function we can call it a method 
var object = { 
method: function() { 
alert(โ€œHere is methodโ€); 
} 
}
Prototype 
โ€ขJavaScript functions work as constructors, methods and 
modules 
โ€ขIt has Prototypal Inheritance, which offers great expressive 
powers 
โ€ขAll Objects are directly or indirectly link to Object.prototype 
โ€ขEach Object is linked to its parent via a magic link 
โ€ขWhen a member is accessed the compiler looks at the 
Object and then looks up to its parent via the magic link 
โ€ขIt keeps going all the way up to Object.prototype 
โ€ขGo to console of firebug and type Object.prototype
Prototype (Con.) 
โ€ขLooking for my_object.foo, found it in the Object itself 
โ€ขLooking for my_object.baz looks in the object and if it 
doesn't find it there it goes to my_object_parent which is 
my_object.prototype 
โ€ขLooking for my_object.some_random_member can't find it in the 
object, look at my_object_parent, can't find it 
โ€ขThere either, goes to Object can't find it there and is set to 
undefined
Prototype (Con.) 
var Person = function() { 
this.name = โ€œMr. Bunlongโ€; 
this.callMe = function() { 
alert(โ€œI am โ€ + this.name); 
} 
} 
var personObj = new Person(); 
personObject.callMe(); 
personObject.constructor(); 
personObject.myFoo(); // will return underfined
Object Augm entation 
โ€ขNew members can be added to any object 
Person.prototype.callMeAgain = function() { 
alert(โ€œI said my name is โ€ + this.name); 
}; 
personObj.callMeAgain();
Prototype Usage 
โ€ขCallMeAgain() is a property of the prototype object 
โ€ขBut it behaves as if it's a prototype of the dude object
Own Properties Vs Prototype's 
โ€ขpersonObj.hasOwnProperty(โ€œcallMeโ€); // will return true 
โ€ขpersonObj.hasOwnProperty(โ€œcallMeAgainโ€); // will return false
isPrototypeOf 
โ€ขPerson.prototype.isPrototypeOf(personObj); // will return true
Inheritance 
โ€ขOOP ensures code reuse 
โ€ขTwo forms of OOP 
โ€ข Classical with Mixin 
โ€ข Prototypal
Prototypal Inheritance 
var Boy = function() {}; 
Boy.prototype = new Person(); 
var boyObj = new Boy(); 
boyObj.callMe();
Inheritance through Mixin 
var Person = function(name) { 
this.greet = function() { 
alert(โ€œHello, I'm โ€ + name); 
} 
}; 
var Employee = function(name) { 
person.apply(this, [name]); 
this.getTeam = function() {return โ€œUI Libraryโ€;} 
} 
// instantiate object of Employee 
var employee = new Employee(โ€œBunlongโ€); 
employee.greet(); 
var team = employee.getTeam(); 
alert(โ€œTeam: โ€ + team);
Singleton 
โ€ขThere is no need to produce a class like constructor for an 
object that will have exactly one instance 
โ€ขThis is typical of JavaScript applications 
โ€ขUse an object literal to get started instead
Module Pattern 
โ€ขThe methods of a singleton can enjoy access to shared 
private datum and private methods 
โ€ขVariables defined in a module are only visible in a module 
โ€ขVariables defined in a function are only visible to the 
function 
โ€ขFunction can be used as module containers
Module Pattern (Con.) 
var myModule = function() { 
var privateVariable, 
privateFunction = function() { 
// coding here 
}; 
return { 
FirstMethod: function() { 
// can access privateVariable 
// can access privateFunction 
} 
} 
}(); 
myModule.firstMethod();
Javascript Object Oriented Programming

More Related Content

What's hot (19)

PPT
Prototype Js
Kivanc Kanturk
ย 
PPT
Object Oriented JavaScript
Donald Sipe
ย 
PDF
Scalable JavaScript Design Patterns
Addy Osmani
ย 
PPT
JavaScript In Object Oriented Way
Borey Lim
ย 
PDF
Future-proofing Your JavaScript Apps (Compact edition)
Addy Osmani
ย 
PDF
JavaScript Objects
Hazem Hagrass
ย 
KEY
Week3
Will Gaybrick
ย 
PPTX
Jquery fundamentals
Salvatore Fazio
ย 
PDF
The Django Book, Chapter 16: django.contrib
Tzu-ping Chung
ย 
PPTX
Javascript Common Design Patterns
Pham Huy Tung
ย 
PPTX
Powerful Generic Patterns With Django
Eric Satterwhite
ย 
PPTX
Introduction to Design Patterns in Javascript
Santhosh Kumar Srinivasan
ย 
PPTX
Javascript for the c# developer
Salvatore Fazio
ย 
PDF
JS Level Up: Prototypes
Vernon Kesner
ย 
PPTX
Object Oriented JavaScript - II
TO THE NEW | Technology
ย 
PDF
[A 3]Javascript oop for xpages developers - public
Kazunori Tatsuki
ย 
PPTX
JavaScript Literacy
David Jacobs
ย 
PPTX
jQuery Data Manipulate API - A source code dissecting journey
Huiyi Yan
ย 
PDF
Metaprogramming + Ds Ls
ArrrrCamp
ย 
Prototype Js
Kivanc Kanturk
ย 
Object Oriented JavaScript
Donald Sipe
ย 
Scalable JavaScript Design Patterns
Addy Osmani
ย 
JavaScript In Object Oriented Way
Borey Lim
ย 
Future-proofing Your JavaScript Apps (Compact edition)
Addy Osmani
ย 
JavaScript Objects
Hazem Hagrass
ย 
Week3
Will Gaybrick
ย 
Jquery fundamentals
Salvatore Fazio
ย 
The Django Book, Chapter 16: django.contrib
Tzu-ping Chung
ย 
Javascript Common Design Patterns
Pham Huy Tung
ย 
Powerful Generic Patterns With Django
Eric Satterwhite
ย 
Introduction to Design Patterns in Javascript
Santhosh Kumar Srinivasan
ย 
Javascript for the c# developer
Salvatore Fazio
ย 
JS Level Up: Prototypes
Vernon Kesner
ย 
Object Oriented JavaScript - II
TO THE NEW | Technology
ย 
[A 3]Javascript oop for xpages developers - public
Kazunori Tatsuki
ย 
JavaScript Literacy
David Jacobs
ย 
jQuery Data Manipulate API - A source code dissecting journey
Huiyi Yan
ย 
Metaprogramming + Ds Ls
ArrrrCamp
ย 

Similar to Javascript Object Oriented Programming (20)

KEY
Javascript tid-bits
David Atchley
ย 
PPTX
Framework prototype
DevMix
ย 
PPTX
Framework prototype
DevMix
ย 
PPTX
Framework prototype
DevMix
ย 
PPTX
Object oriented javascript
Usman Mehmood
ย 
PDF
JavaScript Core
Franรงois Sarradin
ย 
PPT
Beginning Object-Oriented JavaScript
Stoyan Stefanov
ย 
PPTX
JavsScript OOP
LearningTech
ย 
PPT
Advanced Javascript
relay12
ย 
PPT
Advanced Javascript
Manikanda kumar
ย 
PPT
Advanced Javascript
Adieu
ย 
PPT
Advanced JavaScript
Stoyan Stefanov
ย 
PPTX
Ajaxworld
deannalagason
ย 
PDF
JavaScript - Chapter 8 - Objects
WebStackAcademy
ย 
PPTX
JavaScript OOPS Implimentation
Usman Mehmood
ย 
PPTX
Object Oriented Javascript part2
Usman Mehmood
ย 
PPTX
Object oriented javascript
Shah Jalal
ย 
PDF
Prototype 120102020133-phpapp02
plutoone TestTwo
ย 
PPTX
IWT presentation121232112122222225556+556.pptx
dgfs55437
ย 
PPTX
Understanding-Objects-in-Javascript.pptx
MariaTrinidadTumanga
ย 
Javascript tid-bits
David Atchley
ย 
Framework prototype
DevMix
ย 
Framework prototype
DevMix
ย 
Framework prototype
DevMix
ย 
Object oriented javascript
Usman Mehmood
ย 
JavaScript Core
Franรงois Sarradin
ย 
Beginning Object-Oriented JavaScript
Stoyan Stefanov
ย 
JavsScript OOP
LearningTech
ย 
Advanced Javascript
relay12
ย 
Advanced Javascript
Manikanda kumar
ย 
Advanced Javascript
Adieu
ย 
Advanced JavaScript
Stoyan Stefanov
ย 
Ajaxworld
deannalagason
ย 
JavaScript - Chapter 8 - Objects
WebStackAcademy
ย 
JavaScript OOPS Implimentation
Usman Mehmood
ย 
Object Oriented Javascript part2
Usman Mehmood
ย 
Object oriented javascript
Shah Jalal
ย 
Prototype 120102020133-phpapp02
plutoone TestTwo
ย 
IWT presentation121232112122222225556+556.pptx
dgfs55437
ย 
Understanding-Objects-in-Javascript.pptx
MariaTrinidadTumanga
ย 
Ad

More from Bunlong Van (9)

PPT
scrummethodology-151002092252-lva1-app6891
Bunlong Van
ย 
PPT
Scrum methodology
Bunlong Van
ย 
PPT
Javascript dom event
Bunlong Van
ย 
PPT
Basic Javascript
Bunlong Van
ย 
PPT
Real time web and mobile application with Erlang & Ruby programming language
Bunlong Van
ย 
PPT
Why ruby?
Bunlong Van
ย 
PPT
Ruby on Rails testing with Rspec
Bunlong Van
ย 
PPT
How to develop app for facebook fan page
Bunlong Van
ย 
PPT
Why less?
Bunlong Van
ย 
scrummethodology-151002092252-lva1-app6891
Bunlong Van
ย 
Scrum methodology
Bunlong Van
ย 
Javascript dom event
Bunlong Van
ย 
Basic Javascript
Bunlong Van
ย 
Real time web and mobile application with Erlang & Ruby programming language
Bunlong Van
ย 
Why ruby?
Bunlong Van
ย 
Ruby on Rails testing with Rspec
Bunlong Van
ย 
How to develop app for facebook fan page
Bunlong Van
ย 
Why less?
Bunlong Van
ย 
Ad

Recently uploaded (20)

PDF
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
ย 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
ย 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
ย 
PDF
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
ย 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
ย 
PPTX
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
ย 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
ย 
PPTX
CONCEPT OF PROGRAMMING in language .pptx
tamim41
ย 
PDF
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
ย 
PDF
>Wondershare Filmora Crack Free Download 2025
utfefguu
ย 
PDF
The Rise of Sustainable Mobile App Solutions by New York Development Firms
ostechnologies16
ย 
PDF
AWS Consulting Services: Empowering Digital Transformation with Nlineaxis
Nlineaxis IT Solutions Pvt Ltd
ย 
PDF
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
ย 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
ย 
PPTX
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
ย 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
ย 
PPTX
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
ย 
PPTX
computer forensics encase emager app exp6 1.pptx
ssuser343e92
ย 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
ย 
PPTX
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
ย 
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
ย 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
ย 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
ย 
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
ย 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
ย 
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
ย 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
ย 
CONCEPT OF PROGRAMMING in language .pptx
tamim41
ย 
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
ย 
>Wondershare Filmora Crack Free Download 2025
utfefguu
ย 
The Rise of Sustainable Mobile App Solutions by New York Development Firms
ostechnologies16
ย 
AWS Consulting Services: Empowering Digital Transformation with Nlineaxis
Nlineaxis IT Solutions Pvt Ltd
ย 
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
ย 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
ย 
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
ย 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
ย 
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
ย 
computer forensics encase emager app exp6 1.pptx
ssuser343e92
ย 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
ย 
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
ย 

Javascript Object Oriented Programming

  • 1. Click to add Text Javascript Presented by Bunlong VAN http://geekhmer.github.io Object Oriented
  • 3. Object Oriented Basic โ€ขObject (instance): representation of a โ€œthingโ€ (someone or something) โ€ขClass: ablueprint, or recipe for an Object โ€ขEncapsulation: illustrates the fact that an Object contains (encapsulates): โ€ข Data (stored in properties) โ€ข The means to do something with data (using methods) โ€ขInheritance
  • 4. Object Creation โ€ขTwo simple ways var obj = new Object(); obj.name = โ€œFooโ€; obj.say = function() { return โ€œHelloโ€; } var obj = { name: โ€œFooโ€, say: function() { return โ€œHelloโ€; } }
  • 5. Method โ€ขWhen a property is a function we can call it a method var object = { method: function() { alert(โ€œHere is methodโ€); } }
  • 6. Prototype โ€ขJavaScript functions work as constructors, methods and modules โ€ขIt has Prototypal Inheritance, which offers great expressive powers โ€ขAll Objects are directly or indirectly link to Object.prototype โ€ขEach Object is linked to its parent via a magic link โ€ขWhen a member is accessed the compiler looks at the Object and then looks up to its parent via the magic link โ€ขIt keeps going all the way up to Object.prototype โ€ขGo to console of firebug and type Object.prototype
  • 7. Prototype (Con.) โ€ขLooking for my_object.foo, found it in the Object itself โ€ขLooking for my_object.baz looks in the object and if it doesn't find it there it goes to my_object_parent which is my_object.prototype โ€ขLooking for my_object.some_random_member can't find it in the object, look at my_object_parent, can't find it โ€ขThere either, goes to Object can't find it there and is set to undefined
  • 8. Prototype (Con.) var Person = function() { this.name = โ€œMr. Bunlongโ€; this.callMe = function() { alert(โ€œI am โ€ + this.name); } } var personObj = new Person(); personObject.callMe(); personObject.constructor(); personObject.myFoo(); // will return underfined
  • 9. Object Augm entation โ€ขNew members can be added to any object Person.prototype.callMeAgain = function() { alert(โ€œI said my name is โ€ + this.name); }; personObj.callMeAgain();
  • 10. Prototype Usage โ€ขCallMeAgain() is a property of the prototype object โ€ขBut it behaves as if it's a prototype of the dude object
  • 11. Own Properties Vs Prototype's โ€ขpersonObj.hasOwnProperty(โ€œcallMeโ€); // will return true โ€ขpersonObj.hasOwnProperty(โ€œcallMeAgainโ€); // will return false
  • 13. Inheritance โ€ขOOP ensures code reuse โ€ขTwo forms of OOP โ€ข Classical with Mixin โ€ข Prototypal
  • 14. Prototypal Inheritance var Boy = function() {}; Boy.prototype = new Person(); var boyObj = new Boy(); boyObj.callMe();
  • 15. Inheritance through Mixin var Person = function(name) { this.greet = function() { alert(โ€œHello, I'm โ€ + name); } }; var Employee = function(name) { person.apply(this, [name]); this.getTeam = function() {return โ€œUI Libraryโ€;} } // instantiate object of Employee var employee = new Employee(โ€œBunlongโ€); employee.greet(); var team = employee.getTeam(); alert(โ€œTeam: โ€ + team);
  • 16. Singleton โ€ขThere is no need to produce a class like constructor for an object that will have exactly one instance โ€ขThis is typical of JavaScript applications โ€ขUse an object literal to get started instead
  • 17. Module Pattern โ€ขThe methods of a singleton can enjoy access to shared private datum and private methods โ€ขVariables defined in a module are only visible in a module โ€ขVariables defined in a function are only visible to the function โ€ขFunction can be used as module containers
  • 18. Module Pattern (Con.) var myModule = function() { var privateVariable, privateFunction = function() { // coding here }; return { FirstMethod: function() { // can access privateVariable // can access privateFunction } } }(); myModule.firstMethod();