SlideShare a Scribd company logo
OOP in JavaScript “ The World's Most Misunderstood Programming Language” Douglas Crockford
Some Myths JavaScript is related to Java JavaScript was developed by Sun Microsystems JavaScript is not Object Oriented JavaScript does not support data hiding, i.e. everything is public
OOP Concepts Encapsulation Inheritance Polymorphism
Encapsulation Definition Data + Operation Single logically organized unit Data visibility
Inheritance Definition Parent-child relationship between classes Child inherits Parents’ characteristics Child can redefine existing characteristics Child can add more characteristics
Polymorphism Definition Multiple functions Share a common name Context specific invocation The characteristic of being able to assign a different meaning or usage to something in different contexts  ( http://searchsmb.techtarget.com/sDefinition/0,,sid44_gci212803,00.html )
Encapsulation Private variables -  Can only be accessed by private functions and privileged methods Private functions -  Can only be called by privileged methods Privileged methods -  May invoked by code external to the object Public properties -  May be read/written from outside the object Public methods -  Shared methods Prototype properties -  Shared properties
Encapsulation function Student(name) { var age = 0; var checkAge = function(){ return (age > 0) ? age : false; }; this.getAge = function(){  return (checkAge()) ? age : “Age not set”;  } this.setAge = function(_age){ age = _age; } this.name = name; this.constructor.prototype.updateTotal(); } Student.prototype.total = 0; Student.prototype.updateTotal = function(){ this.constructor.prototype.total++; }
Inheritance See Listing 1 See Listing 2
Polymorphism See Listing 1
What more? JSON Closures
JSON Object  – { } Array  – [ ] Separator  –  , : Var students = [ {name :  “abc” ,  age :  20} , {name :  “xyz” ,  age :  21} ];
References http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference http://mckoss.com/jscript/object.htm http://www.sitepoint.com/article/oriented-programming-1 http://www.codeproject.com/aspnet/JsOOP1.asp http://phrogz.net/JS/Classes/OOPinJS.html http://javascript.crockford.com/javascript.html http://kevlindev.com/tutorials/javascript/inheritance/index.htm http://www.dustindiaz.com/javascript-private-public-privileged/ http://developer.yahoo.com/yui/theater/ http://www.dustindiaz.com/json-for-the-masses/ http:// www.json.org / Google + Wikipedia = Many Many more references

More Related Content

What's hot (20)

PDF
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
PDF
Performance Optimization and JavaScript Best Practices
Doris Chen
 
PPTX
Lecture 6: Client Side Programming 2
Artificial Intelligence Institute at UofSC
 
PPTX
Lecture 5: Client Side Programming 1
Artificial Intelligence Institute at UofSC
 
PPTX
Lecture 5 javascript
Mujtaba Haider
 
PPT
Prototype Js
Kivanc Kanturk
 
PPTX
Javascript basics for automation testing
Vikas Thange
 
PPTX
JavaScript Basics - GameCraft Training
Radoslav Georgiev
 
PDF
Advanced JavaScript - Internship Presentation - Week6
Devang Garach
 
PPT
JavaScript Misunderstood
Bhavya Siddappa
 
PPTX
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
PPTX
Introduction to JavaScript Programming
Collaboration Technologies
 
KEY
Object oriented javascript
Garrison Locke
 
PDF
Intro to node.js - Ran Mizrahi (28/8/14)
Ran Mizrahi
 
PDF
JavaScript 101
ygv2000
 
PDF
Paris Web - Javascript as a programming language
Marco Cedaro
 
PPTX
Java script
rajshreemuthiah
 
PPTX
Introduction to JavaScrtipt
sesharao puvvada
 
PDF
JavaScript Good Practices
Jussi Pohjolainen
 
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
Performance Optimization and JavaScript Best Practices
Doris Chen
 
Lecture 6: Client Side Programming 2
Artificial Intelligence Institute at UofSC
 
Lecture 5: Client Side Programming 1
Artificial Intelligence Institute at UofSC
 
Lecture 5 javascript
Mujtaba Haider
 
Prototype Js
Kivanc Kanturk
 
Javascript basics for automation testing
Vikas Thange
 
JavaScript Basics - GameCraft Training
Radoslav Georgiev
 
Advanced JavaScript - Internship Presentation - Week6
Devang Garach
 
JavaScript Misunderstood
Bhavya Siddappa
 
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
Introduction to JavaScript Programming
Collaboration Technologies
 
Object oriented javascript
Garrison Locke
 
Intro to node.js - Ran Mizrahi (28/8/14)
Ran Mizrahi
 
JavaScript 101
ygv2000
 
Paris Web - Javascript as a programming language
Marco Cedaro
 
Java script
rajshreemuthiah
 
Introduction to JavaScrtipt
sesharao puvvada
 
JavaScript Good Practices
Jussi Pohjolainen
 

Viewers also liked (20)

PDF
Data communication computer_network_tutorial
Maulen Bale
 
PPT
The Theory Of The Dom
kaven yan
 
PPT
Ajax Performance
kaven yan
 
PDF
Performance, Games, and Distributed Testing in JavaScript
jeresig
 
KEY
Douglas Crockford - Programming Style and Your Brain
Web Directions
 
PPT
The JSON Saga
kaven yan
 
PDF
Performance Improvements in Browsers
jeresig
 
PPT
Douglas Crockford - Ajax Security
Web Directions
 
PDF
Building a JavaScript Library
jeresig
 
PPT
Json
elliando dias
 
PDF
Good Parts of JavaScript Douglas Crockford
rajivmordani
 
PPT
Advanced Javascript
Adieu
 
PPTX
Advanced JavaScript Concepts
Naresh Kumar
 
PPTX
Computer communication and networks
Imran Khan
 
PPT
Object oriented programming (oop) cs304 power point slides lecture 01
Adil Kakakhel
 
PPT
Object-oriented concepts
BG Java EE Course
 
PPSX
Data communication - Lecture-01
Sehrish Rafiq
 
PDF
Scalable JavaScript Application Architecture
Nicholas Zakas
 
PPT
Linux Administration
Harish1983
 
PDF
CBSE XII Communication And Network Concepts
Guru Ji
 
Data communication computer_network_tutorial
Maulen Bale
 
The Theory Of The Dom
kaven yan
 
Ajax Performance
kaven yan
 
Performance, Games, and Distributed Testing in JavaScript
jeresig
 
Douglas Crockford - Programming Style and Your Brain
Web Directions
 
The JSON Saga
kaven yan
 
Performance Improvements in Browsers
jeresig
 
Douglas Crockford - Ajax Security
Web Directions
 
Building a JavaScript Library
jeresig
 
Good Parts of JavaScript Douglas Crockford
rajivmordani
 
Advanced Javascript
Adieu
 
Advanced JavaScript Concepts
Naresh Kumar
 
Computer communication and networks
Imran Khan
 
Object oriented programming (oop) cs304 power point slides lecture 01
Adil Kakakhel
 
Object-oriented concepts
BG Java EE Course
 
Data communication - Lecture-01
Sehrish Rafiq
 
Scalable JavaScript Application Architecture
Nicholas Zakas
 
Linux Administration
Harish1983
 
CBSE XII Communication And Network Concepts
Guru Ji
 
Ad

Similar to OOP in JavaScript (20)

PPTX
Department of information technology_20250322_133114_0000.pptx
ShreeVarshini12
 
PPTX
Framework prototype
DevMix
 
PPTX
Framework prototype
DevMix
 
PPTX
Framework prototype
DevMix
 
PDF
Object Oriented Programming using JAVA Notes
Uzair Salman
 
ODP
Advanced JavaScript Techniques
Hoat Le
 
PPTX
Functions and Objects in JavaScript
Dhananjay Kumar
 
PPSX
Oop features java presentationshow
ilias ahmed
 
PPTX
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
Sagar Verma
 
PPTX
OOPs in Java
Ranjith Sekar
 
PPTX
Object oriented javascript
Usman Mehmood
 
PPTX
PHP OOP Lecture - 04.pptx
Atikur Rahman
 
PDF
Principles of Object Oriented Programming
Kasun Ranga Wijeweera
 
PDF
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Alena Holligan
 
PPTX
Object Oriented Programming
Iqra khalil
 
PDF
Java inheritance
Hamid Ghorbani
 
PPT
Overview of Object Oriented Programming using C++
jayanthi699330
 
PPT
packages and interfaces
madhavi patil
 
PDF
OOPS JavaScript Interview Questions PDF By ScholarHat
Scholarhat
 
PDF
OOP in PHP
Alena Holligan
 
Department of information technology_20250322_133114_0000.pptx
ShreeVarshini12
 
Framework prototype
DevMix
 
Framework prototype
DevMix
 
Framework prototype
DevMix
 
Object Oriented Programming using JAVA Notes
Uzair Salman
 
Advanced JavaScript Techniques
Hoat Le
 
Functions and Objects in JavaScript
Dhananjay Kumar
 
Oop features java presentationshow
ilias ahmed
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
Sagar Verma
 
OOPs in Java
Ranjith Sekar
 
Object oriented javascript
Usman Mehmood
 
PHP OOP Lecture - 04.pptx
Atikur Rahman
 
Principles of Object Oriented Programming
Kasun Ranga Wijeweera
 
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Alena Holligan
 
Object Oriented Programming
Iqra khalil
 
Java inheritance
Hamid Ghorbani
 
Overview of Object Oriented Programming using C++
jayanthi699330
 
packages and interfaces
madhavi patil
 
OOPS JavaScript Interview Questions PDF By ScholarHat
Scholarhat
 
OOP in PHP
Alena Holligan
 
Ad

More from manugoel2003 (10)

PPT
Css Specificity
manugoel2003
 
PPT
Subversion (SVN)
manugoel2003
 
PPT
Zend Framework
manugoel2003
 
PPT
Drupal CMS
manugoel2003
 
PPT
Securing Your Web Server
manugoel2003
 
PPS
PHP Security
manugoel2003
 
ODP
Introduction to jQuery
manugoel2003
 
ODP
Drupal Best Practices
manugoel2003
 
PPT
CiviCRM
manugoel2003
 
PPT
PHP Documentor
manugoel2003
 
Css Specificity
manugoel2003
 
Subversion (SVN)
manugoel2003
 
Zend Framework
manugoel2003
 
Drupal CMS
manugoel2003
 
Securing Your Web Server
manugoel2003
 
PHP Security
manugoel2003
 
Introduction to jQuery
manugoel2003
 
Drupal Best Practices
manugoel2003
 
CiviCRM
manugoel2003
 
PHP Documentor
manugoel2003
 

Recently uploaded (20)

PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Digital Circuits, important subject in CS
contactparinay1
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 

OOP in JavaScript

  • 1. OOP in JavaScript “ The World's Most Misunderstood Programming Language” Douglas Crockford
  • 2. Some Myths JavaScript is related to Java JavaScript was developed by Sun Microsystems JavaScript is not Object Oriented JavaScript does not support data hiding, i.e. everything is public
  • 3. OOP Concepts Encapsulation Inheritance Polymorphism
  • 4. Encapsulation Definition Data + Operation Single logically organized unit Data visibility
  • 5. Inheritance Definition Parent-child relationship between classes Child inherits Parents’ characteristics Child can redefine existing characteristics Child can add more characteristics
  • 6. Polymorphism Definition Multiple functions Share a common name Context specific invocation The characteristic of being able to assign a different meaning or usage to something in different contexts ( http://searchsmb.techtarget.com/sDefinition/0,,sid44_gci212803,00.html )
  • 7. Encapsulation Private variables - Can only be accessed by private functions and privileged methods Private functions - Can only be called by privileged methods Privileged methods - May invoked by code external to the object Public properties - May be read/written from outside the object Public methods - Shared methods Prototype properties - Shared properties
  • 8. Encapsulation function Student(name) { var age = 0; var checkAge = function(){ return (age > 0) ? age : false; }; this.getAge = function(){ return (checkAge()) ? age : “Age not set”; } this.setAge = function(_age){ age = _age; } this.name = name; this.constructor.prototype.updateTotal(); } Student.prototype.total = 0; Student.prototype.updateTotal = function(){ this.constructor.prototype.total++; }
  • 9. Inheritance See Listing 1 See Listing 2
  • 11. What more? JSON Closures
  • 12. JSON Object – { } Array – [ ] Separator – , : Var students = [ {name : “abc” , age : 20} , {name : “xyz” , age : 21} ];
  • 13. References http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference http://mckoss.com/jscript/object.htm http://www.sitepoint.com/article/oriented-programming-1 http://www.codeproject.com/aspnet/JsOOP1.asp http://phrogz.net/JS/Classes/OOPinJS.html http://javascript.crockford.com/javascript.html http://kevlindev.com/tutorials/javascript/inheritance/index.htm http://www.dustindiaz.com/javascript-private-public-privileged/ http://developer.yahoo.com/yui/theater/ http://www.dustindiaz.com/json-for-the-masses/ http:// www.json.org / Google + Wikipedia = Many Many more references