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
 
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)

PPTX
Introduction to javascript and yoolkui
Khou Suylong
 
PPTX
Advanced JavaScript
Nascenia IT
 
PDF
Prototype 120102020133-phpapp02
plutoone TestTwo
 
PDF
How prototype works in java script?
InnovationM
 
PPTX
Ajaxworld
deannalagason
 
PPTX
JavsScript OOP
LearningTech
 
PDF
JavaScript Essentials
Triphon Statkov
 
PPT
Advanced Javascript
Adieu
 
PPT
Advanced Javascript
Manikanda kumar
 
PPT
Advanced Javascript
relay12
 
PPTX
Javascript talk
Suresh Jayanty
 
PPTX
Javascript Prototypal Inheritance - Big Picture
Manish Jangir
 
PPTX
Lecture 5.pptx
AshutoshTrivedi30
 
PPTX
Learn JS concepts by implementing jQuery
Wingify Engineering
 
PPTX
About Python
Shao-Chuan Wang
 
PPT
Synapseindia object oriented programming in php
Synapseindiappsdevelopment
 
PDF
Javascript foundations: Inheritance
John Hunter
 
PPTX
Class introduction in java
yugandhar vadlamudi
 
PPTX
Java PPT OOPS prepared by Abhinav J.pptx
JainSaab2
 
ODP
(An Extended) Beginners Guide to Object Orientation in PHP
Rick Ogden
 
Introduction to javascript and yoolkui
Khou Suylong
 
Advanced JavaScript
Nascenia IT
 
Prototype 120102020133-phpapp02
plutoone TestTwo
 
How prototype works in java script?
InnovationM
 
Ajaxworld
deannalagason
 
JavsScript OOP
LearningTech
 
JavaScript Essentials
Triphon Statkov
 
Advanced Javascript
Adieu
 
Advanced Javascript
Manikanda kumar
 
Advanced Javascript
relay12
 
Javascript talk
Suresh Jayanty
 
Javascript Prototypal Inheritance - Big Picture
Manish Jangir
 
Lecture 5.pptx
AshutoshTrivedi30
 
Learn JS concepts by implementing jQuery
Wingify Engineering
 
About Python
Shao-Chuan Wang
 
Synapseindia object oriented programming in php
Synapseindiappsdevelopment
 
Javascript foundations: Inheritance
John Hunter
 
Class introduction in java
yugandhar vadlamudi
 
Java PPT OOPS prepared by Abhinav J.pptx
JainSaab2
 
(An Extended) Beginners Guide to Object Orientation in PHP
Rick Ogden
 
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)

PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PPTX
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Import Data Form Excel to Tally Services
Tally xperts
 
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 

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();