SlideShare uma empresa Scribd logo
1 de 17
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

Mais conteúdo relacionado

Mais procurados

JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - ObjectsWebStackAcademy
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesDoris Chen
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascriptGarrison Locke
 
Advanced JavaScript - Internship Presentation - Week6
Advanced JavaScript - Internship Presentation - Week6Advanced JavaScript - Internship Presentation - Week6
Advanced JavaScript - Internship Presentation - Week6Devang Garach
 
Paris Web - Javascript as a programming language
Paris Web - Javascript as a programming languageParis Web - Javascript as a programming language
Paris Web - Javascript as a programming languageMarco Cedaro
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testingVikas Thange
 
Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Ran Mizrahi
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptRangana Sampath
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingRadoslav Georgiev
 
Javascript Best Practices and Intro to Titanium
Javascript Best Practices and Intro to TitaniumJavascript Best Practices and Intro to Titanium
Javascript Best Practices and Intro to TitaniumTechday7
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJamshid Hashimi
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101ygv2000
 
Introduction to JavaScrtipt
Introduction to JavaScrtiptIntroduction to JavaScrtipt
Introduction to JavaScrtiptsesharao puvvada
 

Mais procurados (20)

JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best Practices
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascript
 
Lecture 5 javascript
Lecture 5 javascriptLecture 5 javascript
Lecture 5 javascript
 
Advanced JavaScript - Internship Presentation - Week6
Advanced JavaScript - Internship Presentation - Week6Advanced JavaScript - Internship Presentation - Week6
Advanced JavaScript - Internship Presentation - Week6
 
Prototype Js
Prototype JsPrototype Js
Prototype Js
 
Paris Web - Javascript as a programming language
Paris Web - Javascript as a programming languageParis Web - Javascript as a programming language
Paris Web - Javascript as a programming language
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
 
Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
Introduction to JavaScript Programming
Introduction to JavaScript ProgrammingIntroduction to JavaScript Programming
Introduction to JavaScript Programming
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Java script ppt
Java script pptJava script ppt
Java script ppt
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft Training
 
Javascript Best Practices and Intro to Titanium
Javascript Best Practices and Intro to TitaniumJavascript Best Practices and Intro to Titanium
Javascript Best Practices and Intro to Titanium
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101
 
JavaScript Good Practices
JavaScript Good PracticesJavaScript Good Practices
JavaScript Good Practices
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Introduction to JavaScrtipt
Introduction to JavaScrtiptIntroduction to JavaScrtipt
Introduction to JavaScrtipt
 

Destaque

Bone fractures
Bone fracturesBone fractures
Bone fracturesarivera79
 
Isidorey Technical Introduction
Isidorey Technical IntroductionIsidorey Technical Introduction
Isidorey Technical Introductionkyleroche
 
The reproductive system presentation
The reproductive system presentationThe reproductive system presentation
The reproductive system presentationarivera79
 
Winning and nurturing leads in a web 2.0 environment; ShipServ and why conten...
Winning and nurturing leads in a web 2.0 environment; ShipServ and why conten...Winning and nurturing leads in a web 2.0 environment; ShipServ and why conten...
Winning and nurturing leads in a web 2.0 environment; ShipServ and why conten...John Watton
 
Strategic management #01
Strategic management #01Strategic management #01
Strategic management #01manifeste™
 
Dipsia & uria
Dipsia &  uriaDipsia &  uria
Dipsia & uriaarivera79
 
Lesson8 presentverbs
Lesson8 presentverbsLesson8 presentverbs
Lesson8 presentverbsLauren
 
Final presentation
Final presentationFinal presentation
Final presentationmarshall
 
Open day presentation
Open day presentationOpen day presentation
Open day presentationsallyross
 
American Revolutionary War Heroes
American Revolutionary War HeroesAmerican Revolutionary War Heroes
American Revolutionary War HeroesSharon Matney
 
Roles for my group
Roles for my groupRoles for my group
Roles for my groupsathma
 
In digital space no one can hear you scream
In digital space no one can hear you screamIn digital space no one can hear you scream
In digital space no one can hear you screamJohn Watton
 
3 Montages of different live performances
3 Montages of different live performances3 Montages of different live performances
3 Montages of different live performancessathma
 
2010 SMX Advanced - Advanced CRO Beyond the Landing Page
2010 SMX Advanced - Advanced CRO Beyond the Landing Page2010 SMX Advanced - Advanced CRO Beyond the Landing Page
2010 SMX Advanced - Advanced CRO Beyond the Landing PageVertster.com
 
Social media
Social mediaSocial media
Social mediaAleksis
 
The Router Explained Rroosend
The Router Explained RroosendThe Router Explained Rroosend
The Router Explained Rroosendrroosend
 
FUKUYAMA BASE WORKSHOP Vol13 Theme
FUKUYAMA BASE WORKSHOP Vol13 ThemeFUKUYAMA BASE WORKSHOP Vol13 Theme
FUKUYAMA BASE WORKSHOP Vol13 Themenoteproject
 

Destaque (20)

Bone fractures
Bone fracturesBone fractures
Bone fractures
 
Mn powerpoint
Mn powerpointMn powerpoint
Mn powerpoint
 
Isidorey Technical Introduction
Isidorey Technical IntroductionIsidorey Technical Introduction
Isidorey Technical Introduction
 
The reproductive system presentation
The reproductive system presentationThe reproductive system presentation
The reproductive system presentation
 
Winning and nurturing leads in a web 2.0 environment; ShipServ and why conten...
Winning and nurturing leads in a web 2.0 environment; ShipServ and why conten...Winning and nurturing leads in a web 2.0 environment; ShipServ and why conten...
Winning and nurturing leads in a web 2.0 environment; ShipServ and why conten...
 
Strategic management #01
Strategic management #01Strategic management #01
Strategic management #01
 
Dipsia & uria
Dipsia &  uriaDipsia &  uria
Dipsia & uria
 
Lesson8 presentverbs
Lesson8 presentverbsLesson8 presentverbs
Lesson8 presentverbs
 
Final presentation
Final presentationFinal presentation
Final presentation
 
Open day presentation
Open day presentationOpen day presentation
Open day presentation
 
Microsoft product guide
Microsoft product guideMicrosoft product guide
Microsoft product guide
 
American Revolutionary War Heroes
American Revolutionary War HeroesAmerican Revolutionary War Heroes
American Revolutionary War Heroes
 
Roles for my group
Roles for my groupRoles for my group
Roles for my group
 
Murphy
MurphyMurphy
Murphy
 
In digital space no one can hear you scream
In digital space no one can hear you screamIn digital space no one can hear you scream
In digital space no one can hear you scream
 
3 Montages of different live performances
3 Montages of different live performances3 Montages of different live performances
3 Montages of different live performances
 
2010 SMX Advanced - Advanced CRO Beyond the Landing Page
2010 SMX Advanced - Advanced CRO Beyond the Landing Page2010 SMX Advanced - Advanced CRO Beyond the Landing Page
2010 SMX Advanced - Advanced CRO Beyond the Landing Page
 
Social media
Social mediaSocial media
Social media
 
The Router Explained Rroosend
The Router Explained RroosendThe Router Explained Rroosend
The Router Explained Rroosend
 
FUKUYAMA BASE WORKSHOP Vol13 Theme
FUKUYAMA BASE WORKSHOP Vol13 ThemeFUKUYAMA BASE WORKSHOP Vol13 Theme
FUKUYAMA BASE WORKSHOP Vol13 Theme
 

Semelhante a Object Oriented JavaScript - II

Semelhante a Object Oriented JavaScript - II (20)

jQuery Objects
jQuery ObjectsjQuery Objects
jQuery Objects
 
Spock
SpockSpock
Spock
 
Group111
Group111Group111
Group111
 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdf
 
Best Guide for Javascript Objects
Best Guide for Javascript ObjectsBest Guide for Javascript Objects
Best Guide for Javascript Objects
 
Barcamp Auckland Rails3 presentation
Barcamp Auckland Rails3 presentationBarcamp Auckland Rails3 presentation
Barcamp Auckland Rails3 presentation
 
SystemVerilog_Classes.pdf
SystemVerilog_Classes.pdfSystemVerilog_Classes.pdf
SystemVerilog_Classes.pdf
 
13 java beans
13 java beans13 java beans
13 java beans
 
Codemotion 2015 spock_workshop
Codemotion 2015 spock_workshopCodemotion 2015 spock_workshop
Codemotion 2015 spock_workshop
 
Introduction to java programming
Introduction to java programmingIntroduction to java programming
Introduction to java programming
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptx
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
 
oop 3.pptx
oop 3.pptxoop 3.pptx
oop 3.pptx
 
Core java concepts
Core java conceptsCore java concepts
Core java concepts
 
ppt_on_java.pptx
ppt_on_java.pptxppt_on_java.pptx
ppt_on_java.pptx
 
ClassJS
ClassJSClassJS
ClassJS
 
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1
 
PPT Lecture-1.4.pptx
PPT Lecture-1.4.pptxPPT Lecture-1.4.pptx
PPT Lecture-1.4.pptx
 
Java
JavaJava
Java
 
UNIT - IIInew.pptx
UNIT - IIInew.pptxUNIT - IIInew.pptx
UNIT - IIInew.pptx
 

Mais de TO THE NEW | Technology

10 Best Node.js Practices you Need to Know!
10 Best Node.js Practices you Need to Know!10 Best Node.js Practices you Need to Know!
10 Best Node.js Practices you Need to Know!TO THE NEW | Technology
 
10 Pragmatic UX techniques for building smarter products:
10 Pragmatic UX techniques for building smarter products:10 Pragmatic UX techniques for building smarter products:
10 Pragmatic UX techniques for building smarter products:TO THE NEW | Technology
 
12 Key points which make Swift more effective than Objective C
12 Key points which make Swift more effective than Objective C12 Key points which make Swift more effective than Objective C
12 Key points which make Swift more effective than Objective CTO THE NEW | Technology
 
An introduction to Object Oriented JavaScript
An introduction to Object Oriented JavaScriptAn introduction to Object Oriented JavaScript
An introduction to Object Oriented JavaScriptTO THE NEW | Technology
 
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape SoftwareTO THE NEW | Technology
 
MongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlMongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlTO THE NEW | Technology
 
BigData Search Simplified with ElasticSearch
BigData Search Simplified with ElasticSearchBigData Search Simplified with ElasticSearch
BigData Search Simplified with ElasticSearchTO THE NEW | Technology
 

Mais de TO THE NEW | Technology (20)

10 Best Node.js Practices you Need to Know!
10 Best Node.js Practices you Need to Know!10 Best Node.js Practices you Need to Know!
10 Best Node.js Practices you Need to Know!
 
10 Pragmatic UX techniques for building smarter products:
10 Pragmatic UX techniques for building smarter products:10 Pragmatic UX techniques for building smarter products:
10 Pragmatic UX techniques for building smarter products:
 
12 Key points which make Swift more effective than Objective C
12 Key points which make Swift more effective than Objective C12 Key points which make Swift more effective than Objective C
12 Key points which make Swift more effective than Objective C
 
Gulp - The Streaming Build System
Gulp - The Streaming Build SystemGulp - The Streaming Build System
Gulp - The Streaming Build System
 
Grails Spring Boot
Grails Spring BootGrails Spring Boot
Grails Spring Boot
 
AWS Elastic Beanstalk
AWS Elastic BeanstalkAWS Elastic Beanstalk
AWS Elastic Beanstalk
 
Content migration to AEM
Content migration to AEMContent migration to AEM
Content migration to AEM
 
AWS CodeDeploy
AWS CodeDeployAWS CodeDeploy
AWS CodeDeploy
 
Big Data Expertise
Big Data ExpertiseBig Data Expertise
Big Data Expertise
 
An introduction to Object Oriented JavaScript
An introduction to Object Oriented JavaScriptAn introduction to Object Oriented JavaScript
An introduction to Object Oriented JavaScript
 
MongoDb and NoSQL
MongoDb and NoSQLMongoDb and NoSQL
MongoDb and NoSQL
 
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
 
MongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlMongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behl
 
Cloud Formation
Cloud FormationCloud Formation
Cloud Formation
 
BigData Search Simplified with ElasticSearch
BigData Search Simplified with ElasticSearchBigData Search Simplified with ElasticSearch
BigData Search Simplified with ElasticSearch
 
JULY IN GRAILS
JULY IN GRAILSJULY IN GRAILS
JULY IN GRAILS
 
Grails Spock Testing
Grails Spock TestingGrails Spock Testing
Grails Spock Testing
 
Getting groovier-with-vertx
Getting groovier-with-vertxGetting groovier-with-vertx
Getting groovier-with-vertx
 
Introduction to Kanban
Introduction to KanbanIntroduction to Kanban
Introduction to Kanban
 
Introduction to Heroku
Introduction to HerokuIntroduction to Heroku
Introduction to Heroku
 

Último

COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
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
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
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
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
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
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
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
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 

Último (20)

COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
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
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
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
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
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
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
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
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 

Object Oriented JavaScript - II

  • 1.
  • 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