SlideShare a Scribd company logo
Object Oriented JavaScript - II
BEING A JS NINJA:
Object Oriented
JavaScript
Agenda
1. Functions & Objects
2. Prototype Based Programming
3. Class Based -Prototype Based
4. Method Overloading ?
5. Some hacks
6. Questions
7. Exercises!
Functions ( )
• A SimpleJS function:
• function multiply(a,b){
• return a *b;
• };
• A simple assert function
• Note: A method is a function defined inside an object as its property!
Functions ( )
• JavaScript only has Scope.
• A function has access to all the variables and functions in the scope in
which it isdefined.
• Lets see an example!
• http://jsfiddle.net/suroorwijdan/dr3Bb/2/
this & undefined
“JavaScript has two errors, thisand undefined and whenthisis undefined,
Oh Boy!” - Mikael Rogers
• http://jsfiddle.net/suroorwijdan/6gHjH/4/
Functions ( )
• Closures
• Closures are one of the most powerful weapons for a JS Ninja
• Closures allow a ninja to have access to a function scope with an
exported innerfunction
• http://jsfiddle.net/suroorwijdan/nz9bM/9/
Objects { }
• For a ninja almost everything is an object
• Creating an object:
• Using a Constructor -var obj =new Car();
• Using object initializer -var obj={};
• Using Object.create()
• http://jsfiddle.net/suroorwijdan/p5x2G/
Call and apply
• call() and apply() methods defined on functions allows a Ninja to
change the context in which the function is executed
http://jsfiddle.net/suroorwijdan/XzzU8/
Prototype {} - {} - {}
“Most Confused Upon Part for budding Ninjas”
http://jsfiddle.net/suroorwijdan/h74gd/
Class vs Prototype Based
Class Based(Java) PrototypeBased (JavaScript)
Class and instance are distinct entities All objects are instances
Define a class with a class definition; instantiate
a class with constructor methods
Define and create a set of objects with
constructor functions
Create a single object with the new operator Same
Construct an object hierarchy by using class
definitions to define subclasses of existing
classes
Construct an object hierarchy by
assigning an object as the prototype
associated with a constructor function.
Inherit properties by following the class chain. Inherit properties by following the
prototype chain
Class definition specifies all properties of all
instances of a class. Cannot add properties
dynamically atrun time
Constructor function or prototype
specifies an initial set of properties. Can
add or remove properties dynamically to
individual objects or to the entire set of
objects
Method Overloading ?
Can weimplementmethod overloading inJavaScript,
ifYes, thenHow?? :|
http://jsfiddle.net/suroorwijdan/3xLtY/
Some Hacks!
• Append new array to another array:
• var a =[4,5,6];
• var b =[7,8,9];
• Array.prototype.push.apply(a, b);
• Get TimeStamp with+
• +new Date();
• Access Strings with []just like charAt()
• var a =“This is mytrick”;
• a[0] ==‘T’ //true;
Some Hacks!
• Swap variable values:
• var a =10;
• var b =20;
• [a,b] =[b,a]
And many more :http://code.google.com/p/jslibs/wiki/JavascriptTips
Some More Concepts
• Memoization: “DIY”
• A memorize function is a higher order function which caches the result
returned by the function passed to it
Exercises
• Implement Basic Inheritance with the example of Employee
• Add a forEach method in the prototype of Array
• Implement a function which multiplies the largest number with the first
argument
Contact us
Our Office
Client
Location
We are experts in MEAN
stack framework to build
scalable web apps
Click Here To Know More!
Have more queries related to
MEAN?
Talk To Our Experts

More Related Content

PPT
OOP in JavaScript
manugoel2003
 
PPTX
Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)
raja kvk
 
PPTX
Object Oriented Programming In JavaScript
Forziatech
 
ODP
Object Oriented Javascript
NexThoughts Technologies
 
PDF
JavaScript OOPs
Johnson Chou
 
PDF
Object Oriented Programming in JavaScript
zand3rs
 
PPTX
JavaScript in Object-Oriented Way
Chamnap Chhorn
 
KEY
Week3
Will Gaybrick
 
OOP in JavaScript
manugoel2003
 
Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)
raja kvk
 
Object Oriented Programming In JavaScript
Forziatech
 
Object Oriented Javascript
NexThoughts Technologies
 
JavaScript OOPs
Johnson Chou
 
Object Oriented Programming in JavaScript
zand3rs
 
JavaScript in Object-Oriented Way
Chamnap Chhorn
 

What's hot (20)

PDF
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
PDF
Performance Optimization and JavaScript Best Practices
Doris Chen
 
KEY
Object oriented javascript
Garrison Locke
 
PPTX
Lecture 5 javascript
Mujtaba Haider
 
PDF
Advanced JavaScript - Internship Presentation - Week6
Devang Garach
 
PPT
Prototype Js
Kivanc Kanturk
 
PDF
Paris Web - Javascript as a programming language
Marco Cedaro
 
PPTX
Javascript basics for automation testing
Vikas Thange
 
PDF
Intro to node.js - Ran Mizrahi (28/8/14)
Ran Mizrahi
 
PPTX
Introduction to JavaScript Programming
Collaboration Technologies
 
PPTX
Introduction to JavaScript
Rangana Sampath
 
PPTX
JavaScript Basics - GameCraft Training
Radoslav Georgiev
 
PPTX
Javascript Best Practices and Intro to Titanium
Techday7
 
PPTX
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
PDF
JavaScript 101
ygv2000
 
PDF
JavaScript Good Practices
Jussi Pohjolainen
 
PPTX
JavaScript Basics
Bhanuka Uyanage
 
PPTX
Introduction to JavaScrtipt
sesharao puvvada
 
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
Performance Optimization and JavaScript Best Practices
Doris Chen
 
Object oriented javascript
Garrison Locke
 
Lecture 5 javascript
Mujtaba Haider
 
Advanced JavaScript - Internship Presentation - Week6
Devang Garach
 
Prototype Js
Kivanc Kanturk
 
Paris Web - Javascript as a programming language
Marco Cedaro
 
Javascript basics for automation testing
Vikas Thange
 
Intro to node.js - Ran Mizrahi (28/8/14)
Ran Mizrahi
 
Introduction to JavaScript Programming
Collaboration Technologies
 
Introduction to JavaScript
Rangana Sampath
 
JavaScript Basics - GameCraft Training
Radoslav Georgiev
 
Javascript Best Practices and Intro to Titanium
Techday7
 
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
JavaScript 101
ygv2000
 
JavaScript Good Practices
Jussi Pohjolainen
 
JavaScript Basics
Bhanuka Uyanage
 
Introduction to JavaScrtipt
sesharao puvvada
 
Ad

Viewers also liked (20)

PPTX
Bone fractures
arivera79
 
PPSX
Mn powerpoint
pedronogueira954
 
PDF
Isidorey Technical Introduction
kyleroche
 
PPTX
The reproductive system presentation
arivera79
 
PPTX
Winning and nurturing leads in a web 2.0 environment; ShipServ and why conten...
John Watton
 
PDF
Strategic management #01
manifeste™
 
PPTX
Dipsia & uria
arivera79
 
PPTX
Lesson8 presentverbs
Lauren
 
KEY
Final presentation
marshall
 
PPTX
Open day presentation
sallyross
 
PDF
Microsoft product guide
Securimate, Inc.
 
KEY
American Revolutionary War Heroes
Sharon Matney
 
PPTX
Roles for my group
sathma
 
PPS
Murphy
Rcabellocaja
 
PPTX
In digital space no one can hear you scream
John Watton
 
PPTX
3 Montages of different live performances
sathma
 
PPTX
2010 SMX Advanced - Advanced CRO Beyond the Landing Page
Vertster.com
 
PPT
Social media
Aleksis
 
PPTX
The Router Explained Rroosend
rroosend
 
PPT
FUKUYAMA BASE WORKSHOP Vol13 Theme
noteproject
 
Bone fractures
arivera79
 
Mn powerpoint
pedronogueira954
 
Isidorey Technical Introduction
kyleroche
 
The reproductive system presentation
arivera79
 
Winning and nurturing leads in a web 2.0 environment; ShipServ and why conten...
John Watton
 
Strategic management #01
manifeste™
 
Dipsia & uria
arivera79
 
Lesson8 presentverbs
Lauren
 
Final presentation
marshall
 
Open day presentation
sallyross
 
Microsoft product guide
Securimate, Inc.
 
American Revolutionary War Heroes
Sharon Matney
 
Roles for my group
sathma
 
Murphy
Rcabellocaja
 
In digital space no one can hear you scream
John Watton
 
3 Montages of different live performances
sathma
 
2010 SMX Advanced - Advanced CRO Beyond the Landing Page
Vertster.com
 
Social media
Aleksis
 
The Router Explained Rroosend
rroosend
 
FUKUYAMA BASE WORKSHOP Vol13 Theme
noteproject
 
Ad

Similar to Object Oriented JavaScript - II (20)

PPT
jQuery Objects
Steve Wells
 
PPT
Spock
Gajraj Kalburgi
 
PPTX
Group111
Shahriar Robbani
 
PPTX
Java Classes fact general wireless-19*5.pptx
IbrahimMerzayiee
 
PDF
AJS UNIT-1 2021-converted.pdf
SreeVani74
 
PPT
Best Guide for Javascript Objects
Muhammad khurram khan
 
ZIP
Barcamp Auckland Rails3 presentation
Sociable
 
PDF
SystemVerilog_Classes.pdf
ssusere9cd04
 
PPTX
Lecture 4- Javascript Function presentation
GomathiUdai
 
PPTX
UNIT 3- Java- Inheritance, Multithreading.pptx
shilpar780389
 
PDF
13 java beans
snopteck
 
PDF
Codemotion 2015 spock_workshop
Fernando Redondo Ramírez
 
PPTX
Introduction to java programming
shinyduela
 
PPTX
Unit No 2 Objects and Classes.pptx
DrYogeshDeshmukh1
 
PDF
Raffaele Rialdi
CodeFest
 
PPTX
oop 3.pptx
OsamaMuhammad18
 
PPTX
Core java concepts
laratechnologies
 
PPTX
ppt_on_java.pptx
MAYANKKUMAR492040
 
PDF
ClassJS
Michael Barrett
 
PPTX
Java interview questions 1
Sherihan Anver
 
jQuery Objects
Steve Wells
 
Java Classes fact general wireless-19*5.pptx
IbrahimMerzayiee
 
AJS UNIT-1 2021-converted.pdf
SreeVani74
 
Best Guide for Javascript Objects
Muhammad khurram khan
 
Barcamp Auckland Rails3 presentation
Sociable
 
SystemVerilog_Classes.pdf
ssusere9cd04
 
Lecture 4- Javascript Function presentation
GomathiUdai
 
UNIT 3- Java- Inheritance, Multithreading.pptx
shilpar780389
 
13 java beans
snopteck
 
Codemotion 2015 spock_workshop
Fernando Redondo Ramírez
 
Introduction to java programming
shinyduela
 
Unit No 2 Objects and Classes.pptx
DrYogeshDeshmukh1
 
Raffaele Rialdi
CodeFest
 
oop 3.pptx
OsamaMuhammad18
 
Core java concepts
laratechnologies
 
ppt_on_java.pptx
MAYANKKUMAR492040
 
Java interview questions 1
Sherihan Anver
 

More from TO THE NEW | Technology (20)

PDF
10 Best Node.js Practices you Need to Know!
TO THE NEW | Technology
 
PDF
10 Pragmatic UX techniques for building smarter products:
TO THE NEW | Technology
 
PDF
12 Key points which make Swift more effective than Objective C
TO THE NEW | Technology
 
PDF
Gulp - The Streaming Build System
TO THE NEW | Technology
 
PPTX
Grails Spring Boot
TO THE NEW | Technology
 
PPTX
AWS Elastic Beanstalk
TO THE NEW | Technology
 
PPT
Content migration to AEM
TO THE NEW | Technology
 
PPTX
AWS CodeDeploy
TO THE NEW | Technology
 
PPTX
Big Data Expertise
TO THE NEW | Technology
 
PPTX
An introduction to Object Oriented JavaScript
TO THE NEW | Technology
 
PPTX
MongoDb and NoSQL
TO THE NEW | Technology
 
PPTX
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
TO THE NEW | Technology
 
PPTX
MongoDB using Grails plugin by puneet behl
TO THE NEW | Technology
 
PPTX
Cloud Formation
TO THE NEW | Technology
 
PPTX
BigData Search Simplified with ElasticSearch
TO THE NEW | Technology
 
DOCX
JULY IN GRAILS
TO THE NEW | Technology
 
PPTX
Grails Spock Testing
TO THE NEW | Technology
 
PPTX
Getting groovier-with-vertx
TO THE NEW | Technology
 
PPTX
Introduction to Kanban
TO THE NEW | Technology
 
PPTX
Introduction to Heroku
TO THE NEW | Technology
 
10 Best Node.js Practices you Need to Know!
TO THE NEW | Technology
 
10 Pragmatic UX techniques for building smarter products:
TO THE NEW | Technology
 
12 Key points which make Swift more effective than Objective C
TO THE NEW | Technology
 
Gulp - The Streaming Build System
TO THE NEW | Technology
 
Grails Spring Boot
TO THE NEW | Technology
 
AWS Elastic Beanstalk
TO THE NEW | Technology
 
Content migration to AEM
TO THE NEW | Technology
 
AWS CodeDeploy
TO THE NEW | Technology
 
Big Data Expertise
TO THE NEW | Technology
 
An introduction to Object Oriented JavaScript
TO THE NEW | Technology
 
MongoDb and NoSQL
TO THE NEW | Technology
 
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
TO THE NEW | Technology
 
MongoDB using Grails plugin by puneet behl
TO THE NEW | Technology
 
Cloud Formation
TO THE NEW | Technology
 
BigData Search Simplified with ElasticSearch
TO THE NEW | Technology
 
JULY IN GRAILS
TO THE NEW | Technology
 
Grails Spock Testing
TO THE NEW | Technology
 
Getting groovier-with-vertx
TO THE NEW | Technology
 
Introduction to Kanban
TO THE NEW | Technology
 
Introduction to Heroku
TO THE NEW | Technology
 

Recently uploaded (20)

PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PDF
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
PDF
Study Material and notes for Women Empowerment
ComputerScienceSACWC
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPT
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PPTX
FSSAI (Food Safety and Standards Authority of India) & FDA (Food and Drug Adm...
Dr. Paindla Jyothirmai
 
PPTX
Trends in pediatric nursing .pptx
AneetaSharma15
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
Study Material and notes for Women Empowerment
ComputerScienceSACWC
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
FSSAI (Food Safety and Standards Authority of India) & FDA (Food and Drug Adm...
Dr. Paindla Jyothirmai
 
Trends in pediatric nursing .pptx
AneetaSharma15
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 

Object Oriented JavaScript - II

  • 2. BEING A JS NINJA: Object Oriented JavaScript
  • 3. Agenda 1. Functions & Objects 2. Prototype Based Programming 3. Class Based -Prototype Based 4. Method Overloading ? 5. Some hacks 6. Questions 7. Exercises!
  • 4. Functions ( ) • A SimpleJS function: • function multiply(a,b){ • return a *b; • }; • A simple assert function • Note: A method is a function defined inside an object as its property!
  • 5. Functions ( ) • JavaScript only has Scope. • A function has access to all the variables and functions in the scope in which it isdefined. • Lets see an example! • http://jsfiddle.net/suroorwijdan/dr3Bb/2/
  • 6. this & undefined “JavaScript has two errors, thisand undefined and whenthisis undefined, Oh Boy!” - Mikael Rogers • http://jsfiddle.net/suroorwijdan/6gHjH/4/
  • 7. Functions ( ) • Closures • Closures are one of the most powerful weapons for a JS Ninja • Closures allow a ninja to have access to a function scope with an exported innerfunction • http://jsfiddle.net/suroorwijdan/nz9bM/9/
  • 8. Objects { } • For a ninja almost everything is an object • Creating an object: • Using a Constructor -var obj =new Car(); • Using object initializer -var obj={}; • Using Object.create() • http://jsfiddle.net/suroorwijdan/p5x2G/
  • 9. Call and apply • call() and apply() methods defined on functions allows a Ninja to change the context in which the function is executed http://jsfiddle.net/suroorwijdan/XzzU8/
  • 10. Prototype {} - {} - {} “Most Confused Upon Part for budding Ninjas” http://jsfiddle.net/suroorwijdan/h74gd/
  • 11. Class vs Prototype Based Class Based(Java) PrototypeBased (JavaScript) Class and instance are distinct entities All objects are instances Define a class with a class definition; instantiate a class with constructor methods Define and create a set of objects with constructor functions Create a single object with the new operator Same Construct an object hierarchy by using class definitions to define subclasses of existing classes Construct an object hierarchy by assigning an object as the prototype associated with a constructor function. Inherit properties by following the class chain. Inherit properties by following the prototype chain Class definition specifies all properties of all instances of a class. Cannot add properties dynamically atrun time Constructor function or prototype specifies an initial set of properties. Can add or remove properties dynamically to individual objects or to the entire set of objects
  • 12. Method Overloading ? Can weimplementmethod overloading inJavaScript, ifYes, thenHow?? :| http://jsfiddle.net/suroorwijdan/3xLtY/
  • 13. Some Hacks! • Append new array to another array: • var a =[4,5,6]; • var b =[7,8,9]; • Array.prototype.push.apply(a, b); • Get TimeStamp with+ • +new Date(); • Access Strings with []just like charAt() • var a =“This is mytrick”; • a[0] ==‘T’ //true;
  • 14. Some Hacks! • Swap variable values: • var a =10; • var b =20; • [a,b] =[b,a] And many more :http://code.google.com/p/jslibs/wiki/JavascriptTips
  • 15. Some More Concepts • Memoization: “DIY” • A memorize function is a higher order function which caches the result returned by the function passed to it
  • 16. Exercises • Implement Basic Inheritance with the example of Employee • Add a forEach method in the prototype of Array • Implement a function which multiplies the largest number with the first argument
  • 17. Contact us Our Office Client Location We are experts in MEAN stack framework to build scalable web apps Click Here To Know More! Have more queries related to MEAN? Talk To Our Experts