SlideShare uma empresa Scribd logo
1 de 27
 JavaScript Object.
 JavaScript Functions.
 Self-invoking function.
 JavaScript Prototype.
 Advanced JavaScript.
 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”
};
 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
 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
}();
 “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.
 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

Mais conteúdo relacionado

Mais procurados

Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptzand3rs
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascriptDoeun KOCH
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To ClosureRobert Nyman
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized军 沈
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJWORKS powered by Ordina
 
Javascript Objects Deep Dive
Javascript Objects Deep DiveJavascript Objects Deep Dive
Javascript Objects Deep DiveManish Jangir
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
Javascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big PictureJavascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big PictureManish Jangir
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testingVikas Thange
 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScriptTodd Anglin
 
Interesting Facts About Javascript
Interesting Facts About JavascriptInteresting Facts About Javascript
Interesting Facts About JavascriptManish Jangir
 
Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptForziatech
 
Advanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScriptAdvanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScriptecker
 

Mais procurados (20)

Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScript
 
Java Script Best Practices
Java Script Best PracticesJava Script Best Practices
Java Script Best Practices
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
 
Prototype
PrototypePrototype
Prototype
 
Core concepts-javascript
Core concepts-javascriptCore concepts-javascript
Core concepts-javascript
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To Closure
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized
 
JavaScript Patterns
JavaScript PatternsJavaScript Patterns
JavaScript Patterns
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UX
 
Javascript Objects Deep Dive
Javascript Objects Deep DiveJavascript Objects Deep Dive
Javascript Objects Deep Dive
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Javascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big PictureJavascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big Picture
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScript
 
Interesting Facts About Javascript
Interesting Facts About JavascriptInteresting Facts About Javascript
Interesting Facts About Javascript
 
Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScript
 
Javascript
JavascriptJavascript
Javascript
 
Advanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScriptAdvanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScript
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Iphone course 1
Iphone course 1Iphone course 1
Iphone course 1
 

Semelhante a Understanding Object Oriented Javascript - Coffee@DBG June

Javascriptinobject orientedway-090512225827-phpapp02
Javascriptinobject orientedway-090512225827-phpapp02Javascriptinobject orientedway-090512225827-phpapp02
Javascriptinobject orientedway-090512225827-phpapp02Sopheak Sem
 
Javascript closures
Javascript closures Javascript closures
Javascript closures VNG
 
JavaScript OOPS Implimentation
JavaScript OOPS ImplimentationJavaScript OOPS Implimentation
JavaScript OOPS ImplimentationUsman Mehmood
 
Learn JS concepts by implementing jQuery
Learn JS concepts by implementing jQueryLearn JS concepts by implementing jQuery
Learn JS concepts by implementing jQueryWingify Engineering
 
Design patterns in javascript
Design patterns in javascriptDesign patterns in javascript
Design patterns in javascriptAyush Sharma
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
 
Oop Constructor Destructors Constructor Overloading lecture 2
Oop Constructor  Destructors Constructor Overloading lecture 2Oop Constructor  Destructors Constructor Overloading lecture 2
Oop Constructor Destructors Constructor Overloading lecture 2Abbas Ajmal
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascriptrelay12
 
JavaScript Beyond jQuery
JavaScript Beyond jQueryJavaScript Beyond jQuery
JavaScript Beyond jQueryBobby Bryant
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfacesmadhavi patil
 
The prototype property
The prototype propertyThe prototype property
The prototype propertyHernan Mammana
 
Jquery Plugin
Jquery PluginJquery Plugin
Jquery PluginRavi Mone
 
Paca oops slid
Paca oops slidPaca oops slid
Paca oops slidpacatarpit
 

Semelhante a Understanding Object Oriented Javascript - Coffee@DBG June (20)

Javascriptinobject orientedway-090512225827-phpapp02
Javascriptinobject orientedway-090512225827-phpapp02Javascriptinobject orientedway-090512225827-phpapp02
Javascriptinobject orientedway-090512225827-phpapp02
 
Javascript closures
Javascript closures Javascript closures
Javascript closures
 
Javascript Workshop
Javascript WorkshopJavascript Workshop
Javascript Workshop
 
JavaScript OOPS Implimentation
JavaScript OOPS ImplimentationJavaScript OOPS Implimentation
JavaScript OOPS Implimentation
 
[2015/2016] JavaScript
[2015/2016] JavaScript[2015/2016] JavaScript
[2015/2016] JavaScript
 
Javascript talk
Javascript talkJavascript talk
Javascript talk
 
Learn JS concepts by implementing jQuery
Learn JS concepts by implementing jQueryLearn JS concepts by implementing jQuery
Learn JS concepts by implementing jQuery
 
Ajaxworld
AjaxworldAjaxworld
Ajaxworld
 
Design patterns in javascript
Design patterns in javascriptDesign patterns in javascript
Design patterns in javascript
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Oop Constructor Destructors Constructor Overloading lecture 2
Oop Constructor  Destructors Constructor Overloading lecture 2Oop Constructor  Destructors Constructor Overloading lecture 2
Oop Constructor Destructors Constructor Overloading lecture 2
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
JavaScript
JavaScriptJavaScript
JavaScript
 
JavaScript Beyond jQuery
JavaScript Beyond jQueryJavaScript Beyond jQuery
JavaScript Beyond jQuery
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
 
The prototype property
The prototype propertyThe prototype property
The prototype property
 
Jquery Plugin
Jquery PluginJquery Plugin
Jquery Plugin
 
Paca oops slid
Paca oops slidPaca oops slid
Paca oops slid
 

Mais de Deepu S Nath

Design Thinking, Critical Thinking & Innovation Design
Design Thinking, Critical Thinking & Innovation DesignDesign Thinking, Critical Thinking & Innovation Design
Design Thinking, Critical Thinking & Innovation DesignDeepu S Nath
 
GTECH ATFG µLearn Framework Intro
GTECH ATFG µLearn Framework IntroGTECH ATFG µLearn Framework Intro
GTECH ATFG µLearn Framework IntroDeepu S Nath
 
Future of learning - Technology Disruption
Future of learning  - Technology DisruptionFuture of learning  - Technology Disruption
Future of learning - Technology DisruptionDeepu S Nath
 
Decentralized Applications using Ethereum
Decentralized Applications using EthereumDecentralized Applications using Ethereum
Decentralized Applications using EthereumDeepu S Nath
 
How machines can take decisions
How machines can take decisionsHow machines can take decisions
How machines can take decisionsDeepu S Nath
 
Artificial Intelligence: An Introduction
 Artificial Intelligence: An Introduction Artificial Intelligence: An Introduction
Artificial Intelligence: An IntroductionDeepu S Nath
 
FAYA PORT 80 Introduction
FAYA PORT 80 IntroductionFAYA PORT 80 Introduction
FAYA PORT 80 IntroductionDeepu S Nath
 
How machines can take decisions
How machines can take decisionsHow machines can take decisions
How machines can take decisionsDeepu S Nath
 
Simplified Introduction to AI
Simplified Introduction to AISimplified Introduction to AI
Simplified Introduction to AIDeepu S Nath
 
Mining Opportunities of Block Chain and BitCoin
Mining Opportunities of Block Chain and BitCoinMining Opportunities of Block Chain and BitCoin
Mining Opportunities of Block Chain and BitCoinDeepu S Nath
 
Introduction to DevOps
Introduction to DevOpsIntroduction to DevOps
Introduction to DevOpsDeepu S Nath
 
Coffee@DBG - TechBites March 2016
Coffee@DBG - TechBites March 2016Coffee@DBG - TechBites March 2016
Coffee@DBG - TechBites March 2016Deepu S Nath
 
REACT.JS : Rethinking UI Development Using JavaScript
REACT.JS : Rethinking UI Development Using JavaScriptREACT.JS : Rethinking UI Development Using JavaScript
REACT.JS : Rethinking UI Development Using JavaScriptDeepu S Nath
 
SEO For Developers
SEO For DevelopersSEO For Developers
SEO For DevelopersDeepu S Nath
 
Life Cycle of an App - From Idea to Monetization
Life Cycle of an App - From Idea to Monetization  Life Cycle of an App - From Idea to Monetization
Life Cycle of an App - From Idea to Monetization Deepu S Nath
 
Uncommon Python - What is special in Python
Uncommon Python -  What is special in PythonUncommon Python -  What is special in Python
Uncommon Python - What is special in PythonDeepu S Nath
 
Coffee@DBG - TechBites Sept 2015
Coffee@DBG - TechBites Sept 2015Coffee@DBG - TechBites Sept 2015
Coffee@DBG - TechBites Sept 2015Deepu S Nath
 
Techbites July 2015
Techbites July 2015Techbites July 2015
Techbites July 2015Deepu S Nath
 
Apple Watch - Start Your Developer Engine
Apple Watch -  Start Your Developer EngineApple Watch -  Start Your Developer Engine
Apple Watch - Start Your Developer EngineDeepu S Nath
 
Greetings & Response - English Communication Training
Greetings & Response - English Communication TrainingGreetings & Response - English Communication Training
Greetings & Response - English Communication TrainingDeepu S Nath
 

Mais de Deepu S Nath (20)

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

Último

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 

Último (20)

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 

Understanding Object Oriented Javascript - Coffee@DBG June

  • 1.
  • 2.  JavaScript Object.  JavaScript Functions.  Self-invoking function.  JavaScript Prototype.  Advanced JavaScript.
  • 3.
  • 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” };
  • 7.
  • 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
  • 11.
  • 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 }();
  • 13.
  • 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.
  • 18.
  • 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