SlideShare a Scribd company logo
Object Oriented Programing
in
Akshay Mathur
Akshay Mathur
• Founding Team Member of
– ShopSocially (Enabling “social” for retailers)
– AirTight Neworks (Global leader of WIPS)
• 15+ years in IT industry
– Currently Principal Architect at ShopSocially
– Mostly worked with Startups
• From Conceptualization to Stabilization
• At different functions i.e. development, testing, release
• With multiple technologies
@akshaymathu 2
JS Objects
Objects
• Everything in JS is an object (instance)
“string”.length // 6
“str”.length.toFixed(2) // “3.00”
[„hell‟, „o!‟].join(„‟) // „hello!‟
• Custom objects can also be defined
@akshaymathu 4
Custom Objects
• JavaScript Object has a key and a value
• Key is always string
• Value can be of any type
– Including another JSON object
A = {key1: value1, key2: value2};
or
A = new Object();
A[„key1‟] = value1;
A.key2 = value2;
@akshaymathu 5
Object as Namespace
• It is a good practice to group variables and
functions together in an object rather than
keeping them global
var user = {};
user.name = “Akshay”;
user.greet = function(){
alert(„Hello!„.concat(user.name);
};
@akshaymathu 6
Object as Named Argument
• Objects can be passed to a function as an argument
• They proxy for named arguments
Say_hello = function (options){
if (typeof options === „Object‟){
options.msg = (options.msg)?
options.msg : ‟Hello!‟;
}
alert(options.msg + „ „ + options.name);
}
Say_hello({name: „Akshay‟});
@akshaymathu 7
@akshaymathu 8
JS Functions
Function
• Code block that executes on ‘call’
//define the function
function say_hello(name){
alert(„Hello! „ + name);
}
//call the function
say_hello(„Akshay‟);
@akshaymathu 10
Function Arguments
• Any number of arguments can be passed without
declaring
• Named arguments are not supported
say_hello(1); // Hello! 1
say_hello(); // Hello! undefined
say_hello(„Akshay‟, „Mathur‟);
//Hello! Akshay
@akshaymathu 11
Naming a Function
function my_func(){}
• A function may not have a name
function(){};
my_func = function(){};
@akshaymathu 12
Variable Scope
• By default all variables are global
• Variables defined with ‘var’ keyword are local to
the function
• It is assumed that all variables are defined in the
first line
function(){
var my_var = „Hello‟;
console.log(msg);
var2 = 6;
}
@akshaymathu 13
Return Values
• Anything can be returned from a function
using return statement
function sqr(x){
var sq = x * x;
return sq;
}
var four_sq = sqr(4);
@akshaymathu 14
Other Facts
• A function can be assigned to a variable
• A function can be defined within another function
• A function can return a function
function sqr(){
sq = function (x){
return x * x * x;
};
return sq;
}
My_sqr = sqr(); // function
My_sqr(3); // 27
@akshaymathu 15
16@akshaymathu
JavaScript Classes
Class
• Class is a reserved keyword in JS
– But not implemented
– Same effect is achieved via prototype
• CofeeScript allows to write classes
– Generates JS code using prototype
@akshaymathu 18
Using Functions as Objects
• Functions are actually First Class objects
So we can change
User= {}
User.name = „Akshay‟
User.greet = function(){
alert(„Hello ‟ + User.name)
}
to
User = function(){
this.name = „Akshay‟
this.greet = function(){
alert(„Hello ‟ + this.name)
}
}
@akshaymathu 19
Creating Instances
• Now the object instance can be created using
new keyword
user1 = new User; user1.name
//Akshay user1.greet() //Hello
Akshay
@akshaymathu 20
Object Constructor
• The main object function can take arguments for
initializing properties
User = function(name){
this.name = name;
this.greet = function(){
alert(„Hello ‟ + this.name)
}
}
user1 = new User(„Cerri‟);
user1.greet() //Hello Cerri
@akshaymathu 21
Extending a Class
• More functions and properties can be defined
extending the prototype of the class
User.prototype.setGender =
function(gender){
this.gender = gender;
};
User.prototype.sayGender =
function(){
alert(this.name + „ is ‟ +
this.gender);
};
@akshaymathu 22
Further Reading
• Introduction to Object-Oriented JavaScript on
Mozilla Developer Network
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Introduction_to_Object-
Oriented_JavaScript
Thanks
@akshaymathu 24@akshaymathu
http://www.quora.com/Akshay-Mathur

More Related Content

What's hot (20)

PDF
Workshop 12: AngularJS Parte I
Visual Engineering
 
PPTX
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...
Sencha
 
PPTX
SenchaCon 2016: Ext JS + React: A Match Made in UX Heaven - Mark Brocato
Sencha
 
PDF
Performance Optimization and JavaScript Best Practices
Doris Chen
 
PPTX
Angular JS
John Temoty Roca
 
PDF
jQuery - Chapter 1 - Introduction
WebStackAcademy
 
PDF
Understanding backbonejs
Nick Lee
 
PDF
jQuery - Chapter 3 - Effects
WebStackAcademy
 
PPTX
Angular js
Behind D Walls
 
PDF
Intro to node.js - Ran Mizrahi (28/8/14)
Ran Mizrahi
 
PDF
Kabukiza.tech 1 LT - ScalikeJDBC-Async & Skinny Framework #kbkz_tech
Kazuhiro Sera
 
PDF
Activator and Reactive at Play NYC meetup
Henrik Engström
 
PDF
RESTful OSGi Web Applications Tutorial - Khawaja S Shams & Jeff Norris
mfrancis
 
PDF
jQuery
Ivano Malavolta
 
PDF
Angular - Chapter 7 - HTTP Services
WebStackAcademy
 
PPTX
Javascript first-class citizenery
toddbr
 
PDF
Simplify AJAX using jQuery
Siva Arunachalam
 
PDF
JavaScript - Chapter 7 - Advanced Functions
WebStackAcademy
 
PPTX
AngularJs
syam kumar kk
 
PDF
JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Workshop 12: AngularJS Parte I
Visual Engineering
 
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...
Sencha
 
SenchaCon 2016: Ext JS + React: A Match Made in UX Heaven - Mark Brocato
Sencha
 
Performance Optimization and JavaScript Best Practices
Doris Chen
 
Angular JS
John Temoty Roca
 
jQuery - Chapter 1 - Introduction
WebStackAcademy
 
Understanding backbonejs
Nick Lee
 
jQuery - Chapter 3 - Effects
WebStackAcademy
 
Angular js
Behind D Walls
 
Intro to node.js - Ran Mizrahi (28/8/14)
Ran Mizrahi
 
Kabukiza.tech 1 LT - ScalikeJDBC-Async & Skinny Framework #kbkz_tech
Kazuhiro Sera
 
Activator and Reactive at Play NYC meetup
Henrik Engström
 
RESTful OSGi Web Applications Tutorial - Khawaja S Shams & Jeff Norris
mfrancis
 
Angular - Chapter 7 - HTTP Services
WebStackAcademy
 
Javascript first-class citizenery
toddbr
 
Simplify AJAX using jQuery
Siva Arunachalam
 
JavaScript - Chapter 7 - Advanced Functions
WebStackAcademy
 
AngularJs
syam kumar kk
 
JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 

Similar to Object Oriented Programing in JavaScript (20)

PPTX
Understanding-Objects-in-Javascript.pptx
MariaTrinidadTumanga
 
PPTX
Lecture 4- Javascript Function presentation
GomathiUdai
 
PPTX
JavsScript OOP
LearningTech
 
PPTX
Javascript for the c# developer
Salvatore Fazio
 
PPTX
Awesomeness of JavaScript…almost
Quinton Sheppard
 
PPTX
Javascripts. pptt
RaviShankarSinghal
 
PPT
JavaScript Misunderstood
Bhavya Siddappa
 
PDF
Fii Practic Frontend - BeeNear - laborator3
BeeNear
 
PPTX
Javascript Best Practices and Intro to Titanium
Techday7
 
PDF
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
AAFREEN SHAIKH
 
KEY
Exciting JavaScript - Part I
Eugene Lazutkin
 
PDF
JavaScript Getting Started
Hazem Hagrass
 
PPTX
Cordova training : Day 4 - Advanced Javascript
Binu Paul
 
PPTX
IWT presentation121232112122222225556+556.pptx
dgfs55437
 
PPTX
Javascriptinobject orientedway-090512225827-phpapp02
Sopheak Sem
 
PPTX
JavaScript- Functions and arrays.pptx
Megha V
 
PPTX
Javascript Objects and Functions
Manoj \/ishwakarma
 
PPTX
Javascript Objects and Functions
Gitanjali wagh
 
PPTX
Building maintainable javascript applications
equisodie
 
PDF
full javascript Book by Abhishek singh.pdf
AbhishekSingh961152
 
Understanding-Objects-in-Javascript.pptx
MariaTrinidadTumanga
 
Lecture 4- Javascript Function presentation
GomathiUdai
 
JavsScript OOP
LearningTech
 
Javascript for the c# developer
Salvatore Fazio
 
Awesomeness of JavaScript…almost
Quinton Sheppard
 
Javascripts. pptt
RaviShankarSinghal
 
JavaScript Misunderstood
Bhavya Siddappa
 
Fii Practic Frontend - BeeNear - laborator3
BeeNear
 
Javascript Best Practices and Intro to Titanium
Techday7
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
AAFREEN SHAIKH
 
Exciting JavaScript - Part I
Eugene Lazutkin
 
JavaScript Getting Started
Hazem Hagrass
 
Cordova training : Day 4 - Advanced Javascript
Binu Paul
 
IWT presentation121232112122222225556+556.pptx
dgfs55437
 
Javascriptinobject orientedway-090512225827-phpapp02
Sopheak Sem
 
JavaScript- Functions and arrays.pptx
Megha V
 
Javascript Objects and Functions
Manoj \/ishwakarma
 
Javascript Objects and Functions
Gitanjali wagh
 
Building maintainable javascript applications
equisodie
 
full javascript Book by Abhishek singh.pdf
AbhishekSingh961152
 
Ad

More from Akshay Mathur (18)

PPTX
Documentation with Sphinx
Akshay Mathur
 
PPTX
Kubernetes Journey of a Large FinTech
Akshay Mathur
 
PPTX
Security and Observability of Application Traffic in Kubernetes
Akshay Mathur
 
PPTX
Enhanced Security and Visibility for Microservices Applications
Akshay Mathur
 
PPTX
Considerations for East-West Traffic Security and Analytics for Kubernetes En...
Akshay Mathur
 
PPTX
Kubernetes as Orchestrator for A10 Lightning Controller
Akshay Mathur
 
PPTX
Cloud Bursting with A10 Lightning ADS
Akshay Mathur
 
PPTX
Shared Security Responsibility Model of AWS
Akshay Mathur
 
PPTX
Techniques for scaling application with security and visibility in cloud
Akshay Mathur
 
PPTX
Introduction to Node js
Akshay Mathur
 
PPTX
Getting Started with Angular JS
Akshay Mathur
 
PDF
Releasing Software Without Testing Team
Akshay Mathur
 
PPTX
CoffeeScript
Akshay Mathur
 
PPTX
Getting Started with Web
Akshay Mathur
 
PPTX
Using Google App Engine Python
Akshay Mathur
 
PPTX
Working with GIT
Akshay Mathur
 
PPTX
Testing Single Page Webapp
Akshay Mathur
 
PPTX
Mongo db
Akshay Mathur
 
Documentation with Sphinx
Akshay Mathur
 
Kubernetes Journey of a Large FinTech
Akshay Mathur
 
Security and Observability of Application Traffic in Kubernetes
Akshay Mathur
 
Enhanced Security and Visibility for Microservices Applications
Akshay Mathur
 
Considerations for East-West Traffic Security and Analytics for Kubernetes En...
Akshay Mathur
 
Kubernetes as Orchestrator for A10 Lightning Controller
Akshay Mathur
 
Cloud Bursting with A10 Lightning ADS
Akshay Mathur
 
Shared Security Responsibility Model of AWS
Akshay Mathur
 
Techniques for scaling application with security and visibility in cloud
Akshay Mathur
 
Introduction to Node js
Akshay Mathur
 
Getting Started with Angular JS
Akshay Mathur
 
Releasing Software Without Testing Team
Akshay Mathur
 
CoffeeScript
Akshay Mathur
 
Getting Started with Web
Akshay Mathur
 
Using Google App Engine Python
Akshay Mathur
 
Working with GIT
Akshay Mathur
 
Testing Single Page Webapp
Akshay Mathur
 
Mongo db
Akshay Mathur
 
Ad

Recently uploaded (20)

PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
July Patch Tuesday
Ivanti
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 

Object Oriented Programing in JavaScript

  • 2. Akshay Mathur • Founding Team Member of – ShopSocially (Enabling “social” for retailers) – AirTight Neworks (Global leader of WIPS) • 15+ years in IT industry – Currently Principal Architect at ShopSocially – Mostly worked with Startups • From Conceptualization to Stabilization • At different functions i.e. development, testing, release • With multiple technologies @akshaymathu 2
  • 4. Objects • Everything in JS is an object (instance) “string”.length // 6 “str”.length.toFixed(2) // “3.00” [„hell‟, „o!‟].join(„‟) // „hello!‟ • Custom objects can also be defined @akshaymathu 4
  • 5. Custom Objects • JavaScript Object has a key and a value • Key is always string • Value can be of any type – Including another JSON object A = {key1: value1, key2: value2}; or A = new Object(); A[„key1‟] = value1; A.key2 = value2; @akshaymathu 5
  • 6. Object as Namespace • It is a good practice to group variables and functions together in an object rather than keeping them global var user = {}; user.name = “Akshay”; user.greet = function(){ alert(„Hello!„.concat(user.name); }; @akshaymathu 6
  • 7. Object as Named Argument • Objects can be passed to a function as an argument • They proxy for named arguments Say_hello = function (options){ if (typeof options === „Object‟){ options.msg = (options.msg)? options.msg : ‟Hello!‟; } alert(options.msg + „ „ + options.name); } Say_hello({name: „Akshay‟}); @akshaymathu 7
  • 10. Function • Code block that executes on ‘call’ //define the function function say_hello(name){ alert(„Hello! „ + name); } //call the function say_hello(„Akshay‟); @akshaymathu 10
  • 11. Function Arguments • Any number of arguments can be passed without declaring • Named arguments are not supported say_hello(1); // Hello! 1 say_hello(); // Hello! undefined say_hello(„Akshay‟, „Mathur‟); //Hello! Akshay @akshaymathu 11
  • 12. Naming a Function function my_func(){} • A function may not have a name function(){}; my_func = function(){}; @akshaymathu 12
  • 13. Variable Scope • By default all variables are global • Variables defined with ‘var’ keyword are local to the function • It is assumed that all variables are defined in the first line function(){ var my_var = „Hello‟; console.log(msg); var2 = 6; } @akshaymathu 13
  • 14. Return Values • Anything can be returned from a function using return statement function sqr(x){ var sq = x * x; return sq; } var four_sq = sqr(4); @akshaymathu 14
  • 15. Other Facts • A function can be assigned to a variable • A function can be defined within another function • A function can return a function function sqr(){ sq = function (x){ return x * x * x; }; return sq; } My_sqr = sqr(); // function My_sqr(3); // 27 @akshaymathu 15
  • 18. Class • Class is a reserved keyword in JS – But not implemented – Same effect is achieved via prototype • CofeeScript allows to write classes – Generates JS code using prototype @akshaymathu 18
  • 19. Using Functions as Objects • Functions are actually First Class objects So we can change User= {} User.name = „Akshay‟ User.greet = function(){ alert(„Hello ‟ + User.name) } to User = function(){ this.name = „Akshay‟ this.greet = function(){ alert(„Hello ‟ + this.name) } } @akshaymathu 19
  • 20. Creating Instances • Now the object instance can be created using new keyword user1 = new User; user1.name //Akshay user1.greet() //Hello Akshay @akshaymathu 20
  • 21. Object Constructor • The main object function can take arguments for initializing properties User = function(name){ this.name = name; this.greet = function(){ alert(„Hello ‟ + this.name) } } user1 = new User(„Cerri‟); user1.greet() //Hello Cerri @akshaymathu 21
  • 22. Extending a Class • More functions and properties can be defined extending the prototype of the class User.prototype.setGender = function(gender){ this.gender = gender; }; User.prototype.sayGender = function(){ alert(this.name + „ is ‟ + this.gender); }; @akshaymathu 22
  • 23. Further Reading • Introduction to Object-Oriented JavaScript on Mozilla Developer Network https://developer.mozilla.org/en- US/docs/Web/JavaScript/Introduction_to_Object- Oriented_JavaScript