SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie Object Oriented JavaScript - II

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
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
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
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
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 

Kürzlich hochgeladen (20)

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
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
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
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
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 

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