SlideShare a Scribd company logo
JAVASCRIPT OOP
Introduction //adding a custom property to a prebuilt object var myimage=new Image()  myimage.size="26k"  /*adding a custom property to the custom object "circle"*/ //First, create the custom object "circle" function circle(){ }  var smallcircle=new circle() smallcircle.pi=3.14159   It will not work when a new object will created from circle as not inherited to it.
Using the prototype object to add custom properties to objects //First, create the custom object "circle" function circle(){ }  circle.prototype.pi=3.14159   This is javascript object that helps function to inherit new properties and methods
Using the prototype object to add custom methods to objects //First, create the custom object "circle" function circle(){ } circle.prototype.pi=3.14159 // create the object method. function alertmessage(){ alert(this.pi) } circle.prototype.alertpi=alertmessage
Example  1-Extending functionality to the pre-built string() object   <script type=&quot;text/javascript&quot;> /*code for extending String object with method that writes text backwards*/  //core custom method for writing text backwards  function outputbackwards(){ for (i=this.length-1;i>=0;i--) document.write(this.charAt(i))  }  /Attach custom method to string object  String.prototype.writeback=outputbackwards var message1=&quot;Welcome to my site!&quot;  message1.writeback()  var message2=&quot;Today is a beautiful day&quot;  message2.writeback()  </script>  Output: !etis ym ot emocleW yad lufituaeb a si yadoT
Example 2 Extending functionality to a custom JavaScript object   <script type=&quot;text/javascript&quot;> //create dummy object function dummy(){ } //Create custom property function dummyproperty(){ } //Create custom method function dummymethod(){ }  dummy.prototype.prop=dummyproperty dummy.prototype.method=dummymethod  </script>

More Related Content

PPT
Backbonejs
PDF
构建微信公众平台应用
PDF
Javascript Design Patterns
PDF
Contoh Factory pattern
PPTX
Chapter 3 - part1
PPTX
Object Oriented JavaScript
PDF
Js objects
PDF
JavaScript Inheritance
Backbonejs
构建微信公众平台应用
Javascript Design Patterns
Contoh Factory pattern
Chapter 3 - part1
Object Oriented JavaScript
Js objects
JavaScript Inheritance

Similar to Javascript Oop (20)

PDF
Intro to Ember.js
PDF
Java script object model
PDF
Design patterns in javascript
PDF
Migrating to Angular 2
ODP
Adding To the Leaf Pile
PPTX
MVC Puree - Approaches to MVC with Umbraco
PDF
03 objective-c session 3
PPTX
Class and Object in java core programming
PDF
Object Oriented Programming in JavaScript
PPT
Advanced Javascript
PPT
Advanced Javascript
PPT
Advanced Javascript
PDF
JavaScript Prototype and Module Pattern
PDF
Exercises of java tutoring -version1
PPT
Object Oriented JavaScript
PPT
Advanced Silverlight
PPTX
Oop objects_classes
PDF
Polymer - pleasant client-side programming with web components
PPT
Diving in the Flex Data Binding Waters
PDF
Angularjs - Unit testing introduction
Intro to Ember.js
Java script object model
Design patterns in javascript
Migrating to Angular 2
Adding To the Leaf Pile
MVC Puree - Approaches to MVC with Umbraco
03 objective-c session 3
Class and Object in java core programming
Object Oriented Programming in JavaScript
Advanced Javascript
Advanced Javascript
Advanced Javascript
JavaScript Prototype and Module Pattern
Exercises of java tutoring -version1
Object Oriented JavaScript
Advanced Silverlight
Oop objects_classes
Polymer - pleasant client-side programming with web components
Diving in the Flex Data Binding Waters
Angularjs - Unit testing introduction
Ad

More from mussawir20 (20)

PPT
Php Operators N Controllers
PPT
Php Calling Operators
PPT
Database Design Process
PPT
Php Simple Xml
PPT
Php String And Regular Expressions
PPT
Php Sq Lite
PPT
Php Sessoins N Cookies
PPT
Php Rss
PPT
Php Reusing Code And Writing Functions
PPT
Php Oop
PPT
Php My Sql
PPT
Php File Operations
PPT
Php Error Handling
PPT
Php Crash Course
PPT
Php Basic Security
PPT
Php Using Arrays
PPT
PPT
Javascript
PPT
Object Range
PPT
Prototype Utility Methods(1)
Php Operators N Controllers
Php Calling Operators
Database Design Process
Php Simple Xml
Php String And Regular Expressions
Php Sq Lite
Php Sessoins N Cookies
Php Rss
Php Reusing Code And Writing Functions
Php Oop
Php My Sql
Php File Operations
Php Error Handling
Php Crash Course
Php Basic Security
Php Using Arrays
Javascript
Object Range
Prototype Utility Methods(1)
Ad

Recently uploaded (20)

PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Modernizing your data center with Dell and AMD
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Cloud computing and distributed systems.
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Encapsulation theory and applications.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
NewMind AI Monthly Chronicles - July 2025
Diabetes mellitus diagnosis method based random forest with bat algorithm
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Modernizing your data center with Dell and AMD
Network Security Unit 5.pdf for BCA BBA.
Review of recent advances in non-invasive hemoglobin estimation
Digital-Transformation-Roadmap-for-Companies.pptx
Cloud computing and distributed systems.
Mobile App Security Testing_ A Comprehensive Guide.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Unlocking AI with Model Context Protocol (MCP)
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Building Integrated photovoltaic BIPV_UPV.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Empathic Computing: Creating Shared Understanding
Encapsulation theory and applications.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
20250228 LYD VKU AI Blended-Learning.pptx
Understanding_Digital_Forensics_Presentation.pptx

Javascript Oop

  • 2. Introduction //adding a custom property to a prebuilt object var myimage=new Image() myimage.size=&quot;26k&quot; /*adding a custom property to the custom object &quot;circle&quot;*/ //First, create the custom object &quot;circle&quot; function circle(){ } var smallcircle=new circle() smallcircle.pi=3.14159 It will not work when a new object will created from circle as not inherited to it.
  • 3. Using the prototype object to add custom properties to objects //First, create the custom object &quot;circle&quot; function circle(){ } circle.prototype.pi=3.14159 This is javascript object that helps function to inherit new properties and methods
  • 4. Using the prototype object to add custom methods to objects //First, create the custom object &quot;circle&quot; function circle(){ } circle.prototype.pi=3.14159 // create the object method. function alertmessage(){ alert(this.pi) } circle.prototype.alertpi=alertmessage
  • 5. Example 1-Extending functionality to the pre-built string() object <script type=&quot;text/javascript&quot;> /*code for extending String object with method that writes text backwards*/ //core custom method for writing text backwards function outputbackwards(){ for (i=this.length-1;i>=0;i--) document.write(this.charAt(i)) } /Attach custom method to string object String.prototype.writeback=outputbackwards var message1=&quot;Welcome to my site!&quot; message1.writeback() var message2=&quot;Today is a beautiful day&quot; message2.writeback() </script> Output: !etis ym ot emocleW yad lufituaeb a si yadoT
  • 6. Example 2 Extending functionality to a custom JavaScript object <script type=&quot;text/javascript&quot;> //create dummy object function dummy(){ } //Create custom property function dummyproperty(){ } //Create custom method function dummymethod(){ } dummy.prototype.prop=dummyproperty dummy.prototype.method=dummymethod </script>