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)

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

Similar to Javascript Object Oriented Programming (20)

Introduction to javascript and yoolkui
Introduction to javascript and yoolkuiIntroduction to javascript and yoolkui
Introduction to javascript and yoolkui
Khou Suylong
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
Nascenia IT
 
Prototype 120102020133-phpapp02
Prototype 120102020133-phpapp02Prototype 120102020133-phpapp02
Prototype 120102020133-phpapp02
plutoone TestTwo
 
How prototype works in java script?
How prototype works in java script?How prototype works in java script?
How prototype works in java script?
InnovationM
 
Ajaxworld
AjaxworldAjaxworld
Ajaxworld
deannalagason
 
JavsScript OOP
JavsScript OOPJavsScript OOP
JavsScript OOP
LearningTech
 
JavaScript Essentials
JavaScript EssentialsJavaScript Essentials
JavaScript Essentials
Triphon Statkov
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
Adieu
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
Manikanda kumar
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
relay12
 
Javascript talk
Javascript talkJavascript talk
Javascript talk
Suresh Jayanty
 
Javascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big PictureJavascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big Picture
Manish Jangir
 
Lecture 5.pptx
Lecture 5.pptxLecture 5.pptx
Lecture 5.pptx
AshutoshTrivedi30
 
Learn JS concepts by implementing jQuery
Learn JS concepts by implementing jQueryLearn JS concepts by implementing jQuery
Learn JS concepts by implementing jQuery
Wingify Engineering
 
About Python
About PythonAbout Python
About Python
Shao-Chuan Wang
 
Synapseindia object oriented programming in php
Synapseindia object oriented programming in phpSynapseindia object oriented programming in php
Synapseindia object oriented programming in php
Synapseindiappsdevelopment
 
Javascript foundations: Inheritance
Javascript foundations: InheritanceJavascript foundations: Inheritance
Javascript foundations: Inheritance
John Hunter
 
Class introduction in java
Class introduction in javaClass introduction in java
Class introduction in java
yugandhar vadlamudi
 
Java PPT OOPS prepared by Abhinav J.pptx
Java PPT OOPS prepared by Abhinav J.pptxJava PPT OOPS prepared by Abhinav J.pptx
Java PPT OOPS prepared by Abhinav J.pptx
JainSaab2
 
(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP
Rick Ogden
 
Introduction to javascript and yoolkui
Introduction to javascript and yoolkuiIntroduction to javascript and yoolkui
Introduction to javascript and yoolkui
Khou Suylong
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
Nascenia IT
 
Prototype 120102020133-phpapp02
Prototype 120102020133-phpapp02Prototype 120102020133-phpapp02
Prototype 120102020133-phpapp02
plutoone TestTwo
 
How prototype works in java script?
How prototype works in java script?How prototype works in java script?
How prototype works in java script?
InnovationM
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
Adieu
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
relay12
 
Javascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big PictureJavascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big Picture
Manish Jangir
 
Learn JS concepts by implementing jQuery
Learn JS concepts by implementing jQueryLearn JS concepts by implementing jQuery
Learn JS concepts by implementing jQuery
Wingify Engineering
 
Synapseindia object oriented programming in php
Synapseindia object oriented programming in phpSynapseindia object oriented programming in php
Synapseindia object oriented programming in php
Synapseindiappsdevelopment
 
Javascript foundations: Inheritance
Javascript foundations: InheritanceJavascript foundations: Inheritance
Javascript foundations: Inheritance
John Hunter
 
Java PPT OOPS prepared by Abhinav J.pptx
Java PPT OOPS prepared by Abhinav J.pptxJava PPT OOPS prepared by Abhinav J.pptx
Java PPT OOPS prepared by Abhinav J.pptx
JainSaab2
 
(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP
Rick Ogden
 
Ad

More from Bunlong Van (9)

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

Recently uploaded (20)

Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
Leveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer IntentsLeveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer Intents
Keheliya Gallaba
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
Insurance Tech Services
 
Essentials of Resource Planning in a Downturn
Essentials of Resource Planning in a DownturnEssentials of Resource Planning in a Downturn
Essentials of Resource Planning in a Downturn
OnePlan Solutions
 
Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!
PhilMeredith3
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FMEIntegrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
Topic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptxTopic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptx
marutnand8
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
Revolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management SoftwareRevolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management Software
Insurance Tech Services
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The SequelMarketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
BradBedford3
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Prachi Desai
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlowDevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework
Angelo Theodorou
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptxHow AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
kalichargn70th171
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
Leveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer IntentsLeveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer Intents
Keheliya Gallaba
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
Insurance Tech Services
 
Essentials of Resource Planning in a Downturn
Essentials of Resource Planning in a DownturnEssentials of Resource Planning in a Downturn
Essentials of Resource Planning in a Downturn
OnePlan Solutions
 
Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!
PhilMeredith3
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FMEIntegrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
Topic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptxTopic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptx
marutnand8
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
Revolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management SoftwareRevolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management Software
Insurance Tech Services
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The SequelMarketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
BradBedford3
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Prachi Desai
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlowDevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework
Angelo Theodorou
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptxHow AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
kalichargn70th171
 

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