SlideShare a Scribd company logo
1 of 9
Download to read offline
Javascript Object Oriented Programming

Topics to cover

   JavaScript’s primitive data types
   What an object is in JavaScript
   How to create custom objects
   Object with constructor
   What an object’s prototype property is
     ­ The prototype property allows you to add properties and methods to an 
      object.

                               
 Primitive data types
   Undefined,
   Null,
   Boolean,
   Number, and
   String.




                      
An Object

   An object is a collection of properties
   Properties can either be primitive data types, other 
      objects, or functions

Some built­in objects
   Array
   Image
   Date


                        
Sample usage of in­built objects

   var Image1 = new Image();
   Image1.src = "myDog.gif";


   function myFunc(){
   }
   var myObject = new myFunc(); <br>
   alert(typeof myObject); // displays "object"




                                
Some more sample usage of  objects

  function myFunc(){
   this.StringValue = "This is a String";
  }
  var myObject = new myFunc();
  myObject.StringValue = "This is myObject's string";
  var myObject2 = new myFunc();
  alert(myObject.StringValue); // displays "This is myObject's string"
  alert(myObject2.StringValue); // displays "This is a String"




                               
Sample for constructor

  function myFunc(StringValue){
            this.StringValue = StringValue;
  }


  var myObject = new myFunc("This is myObject's string");
  var myObject2 = new myFunc("This is a String");
  alert(myObject.StringValue); // displays "This is myObject's string"
  alert(myObject2.StringValue); // displays "This is a String"




                               
A Simple custom object
   function Circle(radius){
       this.radius = radius;
       this.getArea = function(){
           return (this.radius*this.radius*3.14);
       }
       this.getCircumference = function(){
           var diameter = this.radius*2;
           var circumference = diameter*3.14;
           return circumference;
       }
   }
   var bigCircle = new Circle(100);
   var smallCircle = new Circle(2);
   alert(bigCircle.getArea()); // displays 31400
   alert(smallCircle.getCircumference()); // displays 12.56
                               
Creating objects using Literal Notation
  timObject = {
  property1 : "Hello",
  property2 : "MmmMMm",
  property3 : ["mmm", 2, 3, 6, "kkk"],
  method1 : function(){alert("Method had been called" + this.property1)}
  };
  timObject.method1();
  alert(timObject.property3[2]) // will yield 3


  var circle = { x : 0, y : 0, radius: 2 } // another example
  // nesting is no problem.


  var rectangle = {
  upperLeft : { x : 2, y : 2 },
  lowerRight : { x : 4, y : 4}
  }
  alert(rectangle.upperLeft.x) // will yield 2
                                   
Subclasses and Superclasses
  function superClass() {
  this.supertest = superTest; //attach method superTest
  }
  function subClass() {
      this.inheritFrom = superClass;
      this.inheritFrom();
      this.subtest = subTest; //attach method subTest
  }
  function superTest() {
      return "superTest";
  }
  function subTest() {
      return "subTest";
  }
  var newClass = new subClass();
  alert(newClass.subtest()); // yields "subTes
  alert(newClass.supertest()); // yields "superTest"
                                 

More Related Content

What's hot

Do something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing appDo something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing appBruce McPherson
 
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheet
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheetDo something in 5 with gas 4- Get your analytics profiles to a spreadsheet
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheetBruce McPherson
 
Ruby on Rails Developer - Allerin
Ruby on Rails Developer - AllerinRuby on Rails Developer - Allerin
Ruby on Rails Developer - AllerinLauree R
 
Learn JS concepts by implementing jQuery
Learn JS concepts by implementing jQueryLearn JS concepts by implementing jQuery
Learn JS concepts by implementing jQueryWingify Engineering
 
Data migration to Drupal using Migrate Module
Data migration to Drupal using Migrate ModuleData migration to Drupal using Migrate Module
Data migration to Drupal using Migrate ModuleSrijan Technologies
 
Is2215 lecture8 relational_databases
Is2215 lecture8 relational_databasesIs2215 lecture8 relational_databases
Is2215 lecture8 relational_databasesdannygriff1
 
Synapse india dotnet development overloading operater part 4
Synapse india dotnet development overloading operater part 4Synapse india dotnet development overloading operater part 4
Synapse india dotnet development overloading operater part 4Synapseindiappsdevelopment
 
Android Cursor Utils - NYC Android Meetup
Android Cursor Utils - NYC Android MeetupAndroid Cursor Utils - NYC Android Meetup
Android Cursor Utils - NYC Android MeetupRon Shapiro
 
Php 5.4: New Language Features You Will Find Useful
Php 5.4: New Language Features You Will Find UsefulPhp 5.4: New Language Features You Will Find Useful
Php 5.4: New Language Features You Will Find UsefulDavid Engel
 
Blank Row Find and Select
Blank Row Find and SelectBlank Row Find and Select
Blank Row Find and SelectRobert Burns
 
NS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt IIINS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt IIIAjit Nayak
 
ActionScript3 collection query API proposal
ActionScript3 collection query API proposalActionScript3 collection query API proposal
ActionScript3 collection query API proposalSlavisa Pokimica
 
New text document
New text documentNew text document
New text documentTam Ngo
 
Stat Design3 18 09
Stat Design3 18 09Stat Design3 18 09
Stat Design3 18 09stat
 
JavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerJavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerBruce McPherson
 

What's hot (20)

Do something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing appDo something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing app
 
Clojure functions midje
Clojure functions midjeClojure functions midje
Clojure functions midje
 
I os 04
I os 04I os 04
I os 04
 
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheet
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheetDo something in 5 with gas 4- Get your analytics profiles to a spreadsheet
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheet
 
Ruby on Rails Developer - Allerin
Ruby on Rails Developer - AllerinRuby on Rails Developer - Allerin
Ruby on Rails Developer - Allerin
 
Learn JS concepts by implementing jQuery
Learn JS concepts by implementing jQueryLearn JS concepts by implementing jQuery
Learn JS concepts by implementing jQuery
 
Data migration to Drupal using Migrate Module
Data migration to Drupal using Migrate ModuleData migration to Drupal using Migrate Module
Data migration to Drupal using Migrate Module
 
Is2215 lecture8 relational_databases
Is2215 lecture8 relational_databasesIs2215 lecture8 relational_databases
Is2215 lecture8 relational_databases
 
Backbonejs
BackbonejsBackbonejs
Backbonejs
 
Synapse india dotnet development overloading operater part 4
Synapse india dotnet development overloading operater part 4Synapse india dotnet development overloading operater part 4
Synapse india dotnet development overloading operater part 4
 
Android Cursor Utils - NYC Android Meetup
Android Cursor Utils - NYC Android MeetupAndroid Cursor Utils - NYC Android Meetup
Android Cursor Utils - NYC Android Meetup
 
Php 5.4: New Language Features You Will Find Useful
Php 5.4: New Language Features You Will Find UsefulPhp 5.4: New Language Features You Will Find Useful
Php 5.4: New Language Features You Will Find Useful
 
Blank Row Find and Select
Blank Row Find and SelectBlank Row Find and Select
Blank Row Find and Select
 
NS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt IIINS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt III
 
Moar tools for asynchrony!
Moar tools for asynchrony!Moar tools for asynchrony!
Moar tools for asynchrony!
 
ActionScript3 collection query API proposal
ActionScript3 collection query API proposalActionScript3 collection query API proposal
ActionScript3 collection query API proposal
 
New text document
New text documentNew text document
New text document
 
Stat Design3 18 09
Stat Design3 18 09Stat Design3 18 09
Stat Design3 18 09
 
Angular2 rxjs
Angular2 rxjsAngular2 rxjs
Angular2 rxjs
 
JavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerJavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primer
 

Viewers also liked

Report splinternetmarketing.com internet marketing 3-7-2012
Report splinternetmarketing.com internet marketing   3-7-2012Report splinternetmarketing.com internet marketing   3-7-2012
Report splinternetmarketing.com internet marketing 3-7-2012SplinternetMarketing.com
 
Building for multiple devices using a single language and framework
Building for multiple devices using a single language and frameworkBuilding for multiple devices using a single language and framework
Building for multiple devices using a single language and frameworkFabian Frank
 
NHM Limited: Company Presentation
NHM Limited: Company PresentationNHM Limited: Company Presentation
NHM Limited: Company PresentationNHM Limited
 
Pseudo-dynamic website with Movable Type
Pseudo-dynamic website with Movable TypePseudo-dynamic website with Movable Type
Pseudo-dynamic website with Movable TypeDaiji Hirata
 
JS Loading strategies
JS Loading strategiesJS Loading strategies
JS Loading strategiesCaridy Patino
 
JSConfBR - Securing Node.js App, by the community and for the community
JSConfBR - Securing Node.js App, by the community and for the community JSConfBR - Securing Node.js App, by the community and for the community
JSConfBR - Securing Node.js App, by the community and for the community David Dias
 
Node.js Cloud deployment
Node.js Cloud deploymentNode.js Cloud deployment
Node.js Cloud deploymentNicholas McClay
 
Build your web apps with yql and yui
Build your web apps with yql and yuiBuild your web apps with yql and yui
Build your web apps with yql and yuiISOCHK
 
LNG pricing: how to get it right in a volatile energy market
LNG pricing: how to get it right in a volatile energy marketLNG pricing: how to get it right in a volatile energy market
LNG pricing: how to get it right in a volatile energy marketRudolf Huber
 
Create simple api using node js
Create simple api using node jsCreate simple api using node js
Create simple api using node jsEdwin Andrianto
 
Ecosystem Environment for Starting a Semiconductor Company
Ecosystem Environment for Starting a Semiconductor CompanyEcosystem Environment for Starting a Semiconductor Company
Ecosystem Environment for Starting a Semiconductor CompanySteve Szirom
 
1seg - mobile digital TV in Japan
1seg - mobile digital TV in Japan1seg - mobile digital TV in Japan
1seg - mobile digital TV in JapanGerhard Fasol
 
Being HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on PurposeBeing HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on PurposeAman Kohli
 
Testing & Deploying node.js apps
Testing & Deploying node.js appsTesting & Deploying node.js apps
Testing & Deploying node.js appsSteven Beeckman
 
Polyglot Gradle with Node.js and Play
Polyglot Gradle with Node.js and PlayPolyglot Gradle with Node.js and Play
Polyglot Gradle with Node.js and PlayEvgeny Goldin
 

Viewers also liked (20)

Report splinternetmarketing.com internet marketing 3-7-2012
Report splinternetmarketing.com internet marketing   3-7-2012Report splinternetmarketing.com internet marketing   3-7-2012
Report splinternetmarketing.com internet marketing 3-7-2012
 
japan teacher
japan teacherjapan teacher
japan teacher
 
Building for multiple devices using a single language and framework
Building for multiple devices using a single language and frameworkBuilding for multiple devices using a single language and framework
Building for multiple devices using a single language and framework
 
NHM Limited: Company Presentation
NHM Limited: Company PresentationNHM Limited: Company Presentation
NHM Limited: Company Presentation
 
Pseudo-dynamic website with Movable Type
Pseudo-dynamic website with Movable TypePseudo-dynamic website with Movable Type
Pseudo-dynamic website with Movable Type
 
JS Loading strategies
JS Loading strategiesJS Loading strategies
JS Loading strategies
 
Who is Tammy Reid & why use Equipment Finance
Who is Tammy Reid & why use Equipment FinanceWho is Tammy Reid & why use Equipment Finance
Who is Tammy Reid & why use Equipment Finance
 
JSConfBR - Securing Node.js App, by the community and for the community
JSConfBR - Securing Node.js App, by the community and for the community JSConfBR - Securing Node.js App, by the community and for the community
JSConfBR - Securing Node.js App, by the community and for the community
 
Node.js Cloud deployment
Node.js Cloud deploymentNode.js Cloud deployment
Node.js Cloud deployment
 
Build your web apps with yql and yui
Build your web apps with yql and yuiBuild your web apps with yql and yui
Build your web apps with yql and yui
 
Yui mobile
Yui mobileYui mobile
Yui mobile
 
LNG pricing: how to get it right in a volatile energy market
LNG pricing: how to get it right in a volatile energy marketLNG pricing: how to get it right in a volatile energy market
LNG pricing: how to get it right in a volatile energy market
 
Create simple api using node js
Create simple api using node jsCreate simple api using node js
Create simple api using node js
 
Ecosystem Environment for Starting a Semiconductor Company
Ecosystem Environment for Starting a Semiconductor CompanyEcosystem Environment for Starting a Semiconductor Company
Ecosystem Environment for Starting a Semiconductor Company
 
1seg - mobile digital TV in Japan
1seg - mobile digital TV in Japan1seg - mobile digital TV in Japan
1seg - mobile digital TV in Japan
 
Being HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on PurposeBeing HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on Purpose
 
YUI for your Hacks
YUI for your Hacks YUI for your Hacks
YUI for your Hacks
 
Testing & Deploying node.js apps
Testing & Deploying node.js appsTesting & Deploying node.js apps
Testing & Deploying node.js apps
 
Polyglot Gradle with Node.js and Play
Polyglot Gradle with Node.js and PlayPolyglot Gradle with Node.js and Play
Polyglot Gradle with Node.js and Play
 
Testing with Node.js
Testing with Node.jsTesting with Node.js
Testing with Node.js
 

Similar to Js objects

Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScriptkvangork
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascriptkvangork
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScriptJulie Iskander
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oopLearningTech
 
Js 单元测试框架介绍
Js 单元测试框架介绍Js 单元测试框架介绍
Js 单元测试框架介绍louieuser
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montageKris Kowal
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced JavascriptAdieu
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascriptrelay12
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesAnkit Rastogi
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」matuura_core
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Tsuyoshi Yamamoto
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScriptDonald Sipe
 
Architecting JavaScript Code
Architecting JavaScript CodeArchitecting JavaScript Code
Architecting JavaScript CodeSuresh Balla
 
The Ring programming language version 1.7 book - Part 16 of 196
The Ring programming language version 1.7 book - Part 16 of 196The Ring programming language version 1.7 book - Part 16 of 196
The Ring programming language version 1.7 book - Part 16 of 196Mahmoud Samir Fayed
 

Similar to Js objects (20)

Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScript
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascript
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
 
Js 单元测试框架介绍
Js 单元测试框架介绍Js 单元测试框架介绍
Js 单元测试框架介绍
 
Say It With Javascript
Say It With JavascriptSay It With Javascript
Say It With Javascript
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montage
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Javascript
JavascriptJavascript
Javascript
 
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
 
Advanced JavaScript
Advanced JavaScript Advanced JavaScript
Advanced JavaScript
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Architecting JavaScript Code
Architecting JavaScript CodeArchitecting JavaScript Code
Architecting JavaScript Code
 
Ext J S Observable
Ext J S ObservableExt J S Observable
Ext J S Observable
 
The Ring programming language version 1.7 book - Part 16 of 196
The Ring programming language version 1.7 book - Part 16 of 196The Ring programming language version 1.7 book - Part 16 of 196
The Ring programming language version 1.7 book - Part 16 of 196
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 

Recently uploaded (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 

Js objects

  • 1. Javascript Object Oriented Programming Topics to cover  JavaScript’s primitive data types  What an object is in JavaScript  How to create custom objects  Object with constructor  What an object’s prototype property is  ­ The prototype property allows you to add properties and methods to an  object.    
  • 2.  Primitive data types  Undefined,  Null,  Boolean,  Number, and  String.    
  • 3. An Object  An object is a collection of properties  Properties can either be primitive data types, other  objects, or functions Some built­in objects  Array  Image  Date    
  • 4. Sample usage of in­built objects var Image1 = new Image(); Image1.src = "myDog.gif"; function myFunc(){ } var myObject = new myFunc(); <br> alert(typeof myObject); // displays "object"    
  • 5. Some more sample usage of  objects function myFunc(){ this.StringValue = "This is a String"; } var myObject = new myFunc(); myObject.StringValue = "This is myObject's string"; var myObject2 = new myFunc(); alert(myObject.StringValue); // displays "This is myObject's string" alert(myObject2.StringValue); // displays "This is a String"    
  • 6. Sample for constructor function myFunc(StringValue){ this.StringValue = StringValue; } var myObject = new myFunc("This is myObject's string"); var myObject2 = new myFunc("This is a String"); alert(myObject.StringValue); // displays "This is myObject's string" alert(myObject2.StringValue); // displays "This is a String"    
  • 7. A Simple custom object function Circle(radius){ this.radius = radius; this.getArea = function(){ return (this.radius*this.radius*3.14); } this.getCircumference = function(){ var diameter = this.radius*2; var circumference = diameter*3.14; return circumference; } } var bigCircle = new Circle(100); var smallCircle = new Circle(2); alert(bigCircle.getArea()); // displays 31400 alert(smallCircle.getCircumference()); // displays 12.56    
  • 8. Creating objects using Literal Notation timObject = { property1 : "Hello", property2 : "MmmMMm", property3 : ["mmm", 2, 3, 6, "kkk"], method1 : function(){alert("Method had been called" + this.property1)} }; timObject.method1(); alert(timObject.property3[2]) // will yield 3 var circle = { x : 0, y : 0, radius: 2 } // another example // nesting is no problem. var rectangle = { upperLeft : { x : 2, y : 2 }, lowerRight : { x : 4, y : 4} } alert(rectangle.upperLeft.x) // will yield 2    
  • 9. Subclasses and Superclasses function superClass() { this.supertest = superTest; //attach method superTest } function subClass() { this.inheritFrom = superClass; this.inheritFrom(); this.subtest = subTest; //attach method subTest } function superTest() { return "superTest"; } function subTest() { return "subTest"; } var newClass = new subClass(); alert(newClass.subtest()); // yields "subTes alert(newClass.supertest()); // yields "superTest"