SlideShare a Scribd company logo
inheritence
in
Javascript
Aditya Gaur
Mentor: Apurba Nath, Satya Prakash
Why inheritence ?
 Creating a hierarchy
 Code reuse
Classical inheritance
Objects are instances of classes
A Class inherits from other class
Prototypal inheritance
A prototypal language is a class less object
oriented language.
 OOP without classes – now that’s weird
Here Objects inherit from objects
 What could be more object oriented than this!
 Code reuse done via cloning
How do we do this?
prototype
A prototype is an object used to implement
structure, state, and behaviour inheritance in
ECMAScript.
So, what kind of
objects contain the
prototype object?
Each and every object
(Except the Object.prototype)
What !But when I do { }.prototype, I get null
:-/
So what is prototype actually?
The true prototype of an object is held by the
internal [[Prototype]] property.
This is represented as __proto__ in some of
the browsers like firefox.
__proto__
oldObjectnewObject
Accessing the prototype
Most browsers support the non standard
accessor __proto__ .
ECMA 5 introduces the standard accessor
Object.getPrototypeOf(object)
Use object constructor.
object.constructor.prototype
Example
var baseObject = {
firstMethod: function () {alert(“first method");},
secondMethod: function () {alert(“second method");}
};
var extendedObject = {};
extendedObject.thirdMethod = function () {alert(“third method")};
extendedObject.__proto__ = baseObject;
extendedObject.firstMethod();
extendedObject.thirdMethod();
firstMethod
secondMethod
__proto__
thirdMethod
__proto__
baseObjectextendedObject
Prototype chaining
When an object is asked to evaluate property foo,
JavaScript walks the prototype chain (starting with
object a itself), checking each link in the chain for the
presence of property foo.
If and when foo is found it is returned, otherwise
undefined is returned.
var baseObject = {
name: "FooBarBaz",
getModifiedString : function(){
return "Hello " + this.name;
}
};
var extendedObject = {
age : 10
};
extendedObject.__proto__ = baseObject;
extendedObject.getModifiedString();
extendedObject.toString();
name
getModifiedString
__proto__
age
__proto__
baseObject
extendedObject
toString
__proto__
Object.prototype
null
OK, So what was the prototype we were
talking about in the last session?
Prototype property in functions
var newClass = function (){
var privateVal = 10;
this.publicVal = 20;
}
newClass.prototype.sharedVal = 30;
what's this?
 The functions in JavaScript are objects and they
contain methods and properties.
 One of property of the function objects is prototype.
 A function’s prototype property is the object that will
be assigned as the prototype ([[Prototype]] ) to all
instances created when this function is used as a
constructor.
examples
//function will never be a constructor but it has a prototype
property anyway
Math.max.prototype; //[object Object]
//function intended to be a constructor has a prototype too
var A = function(name) {
this.name = name;
}
A.prototype; //[object Object]
//Math is not a function so no prototype property
Math.prototype; //null
 Every function has a prototype property, and the
objects which are not function don’t have the prototype
property.
examples
function Foo(name){
this.name = name;
}
Foo.prototype.getName = function(){
return this.name;
}
var obj = new Foo("bar");
obj.getName();
Foo
prototype
__proto__
constructor
getName
obj
name
__proto__
Function.prototype
Examples (augmentation)
function Foo(name){
this.name = name;
}
Foo.prototype.getName = function(){
return this.name;
};
var obj = new Foo("bar");
obj.getName(); //bar
Foo.prototype.getFullName = function(){
return "Foo" + this.name;
};
obj.getFullName();// Foobar
 Note that the prototype is "live". Objects are passed by reference in
JavaScript, and therefore the prototype is not copied with every new
object instance.
 It means that prototype property can be changed at any time and
all the instances will reflect the change.
A catch
function Foo(name){
this.name = name;
}
Foo.prototype.getName = function(){
return this.name;
};
var obj = new Foo("bar");
obj.getName(); //bar
Foo.prototype = {
getFullName : function (){
return "FOO" + this.name;
}
};
obj.getFullName();// ERROR
obj.getName(); //bar
var obj2 = new Foo("baz");
obj2.getFullName(); //FOObaz
 If the prototype property is completely replaced the object still
points to the original prototype ([[Prototype]] )
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
 Creates a new object with the specified prototype object and
properties
 Introduced in ECMAscript 5.
Object.create
var func = function(){
alert(this);
this.aVar =10;
}
var aVar = func();
 The new keyword.
 If we forget the new keyword, “this” is bounded to global object.
 Also gives an impression of classical inheritance
 Deprecated __proto__
Object.create. Why ?
 Douglas Crockford’s video lecture on Advanced
javascript
 Mozilla developer network
References
Thank you

More Related Content

What's hot

Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScript
zand3rs
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
Fu Cheng
 
Javascript basic course
Javascript basic courseJavascript basic course
Javascript basic course
Tran Khoa
 
Assign
AssignAssign
Assign
EMSNEWS
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
Stoyan Stefanov
 
Javascript tid-bits
Javascript tid-bitsJavascript tid-bits
Javascript tid-bits
David Atchley
 
JavaScript Inheritance
JavaScript InheritanceJavaScript Inheritance
JavaScript Inheritance
Jussi Pohjolainen
 
Introduction to modern c++ principles(part 1)
Introduction to modern c++ principles(part 1)Introduction to modern c++ principles(part 1)
Introduction to modern c++ principles(part 1)
Oky Firmansyah
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScript
Stoyan Stefanov
 
PyFoursquare: Python Library for Foursquare
PyFoursquare: Python Library for FoursquarePyFoursquare: Python Library for Foursquare
PyFoursquare: Python Library for Foursquare
Marcel Caraciolo
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 
JavaScript Primer
JavaScript PrimerJavaScript Primer
JavaScript Primer
Daniel Cousineau
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
Abbas Raza
 
JavaScript 1 for high school
JavaScript 1 for high schoolJavaScript 1 for high school
JavaScript 1 for high school
jekkilekki
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
Mindfire Solutions
 
Real world gobbledygook
Real world gobbledygookReal world gobbledygook
Real world gobbledygook
Pawel Szulc
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
Mats Bryntse
 
Beyond Java: 자바 8을 중심으로 본 자바의 혁신
Beyond Java: 자바 8을 중심으로 본 자바의 혁신Beyond Java: 자바 8을 중심으로 본 자바의 혁신
Beyond Java: 자바 8을 중심으로 본 자바의 혁신
Sungchul Park
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
Santosh Rajan
 
About Python
About PythonAbout Python
About Python
Shao-Chuan Wang
 

What's hot (20)

Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScript
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Javascript basic course
Javascript basic courseJavascript basic course
Javascript basic course
 
Assign
AssignAssign
Assign
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Javascript tid-bits
Javascript tid-bitsJavascript tid-bits
Javascript tid-bits
 
JavaScript Inheritance
JavaScript InheritanceJavaScript Inheritance
JavaScript Inheritance
 
Introduction to modern c++ principles(part 1)
Introduction to modern c++ principles(part 1)Introduction to modern c++ principles(part 1)
Introduction to modern c++ principles(part 1)
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScript
 
PyFoursquare: Python Library for Foursquare
PyFoursquare: Python Library for FoursquarePyFoursquare: Python Library for Foursquare
PyFoursquare: Python Library for Foursquare
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
JavaScript Primer
JavaScript PrimerJavaScript Primer
JavaScript Primer
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
JavaScript 1 for high school
JavaScript 1 for high schoolJavaScript 1 for high school
JavaScript 1 for high school
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
 
Real world gobbledygook
Real world gobbledygookReal world gobbledygook
Real world gobbledygook
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Beyond Java: 자바 8을 중심으로 본 자바의 혁신
Beyond Java: 자바 8을 중심으로 본 자바의 혁신Beyond Java: 자바 8을 중심으로 본 자바의 혁신
Beyond Java: 자바 8을 중심으로 본 자바의 혁신
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
About Python
About PythonAbout Python
About Python
 

Viewers also liked

123456
123456123456
this is message edit and approve
this is message edit and approvethis is message edit and approve
this is message edit and approve
plutoone TestTwo
 
LAtest Doc
LAtest DocLAtest Doc
LAtest Doc
plutoone TestTwo
 
Presentation1.PPTX
Presentation1.PPTXPresentation1.PPTX
Presentation1.PPTX
plutoone TestTwo
 
Presentation1.PPTX
Presentation1.PPTXPresentation1.PPTX
Presentation1.PPTX
plutoone TestTwo
 
Scare at 13:59
Scare at 13:59Scare at 13:59
Scare at 13:59
plutoone TestTwo
 
Sam_V01.ppt
Sam_V01.pptSam_V01.ppt
Sam_V01.ppt
plutoone TestTwo
 

Viewers also liked (7)

123456
123456123456
123456
 
this is message edit and approve
this is message edit and approvethis is message edit and approve
this is message edit and approve
 
LAtest Doc
LAtest DocLAtest Doc
LAtest Doc
 
Presentation1.PPTX
Presentation1.PPTXPresentation1.PPTX
Presentation1.PPTX
 
Presentation1.PPTX
Presentation1.PPTXPresentation1.PPTX
Presentation1.PPTX
 
Scare at 13:59
Scare at 13:59Scare at 13:59
Scare at 13:59
 
Sam_V01.ppt
Sam_V01.pptSam_V01.ppt
Sam_V01.ppt
 

Similar to Prototype 120102020133-phpapp02

Introduction to javascript and yoolkui
Introduction to javascript and yoolkuiIntroduction to javascript and yoolkui
Introduction to javascript and yoolkui
Khou Suylong
 
The many facets of code reuse in JavaScript
The many facets of code reuse in JavaScriptThe many facets of code reuse in JavaScript
The many facets of code reuse in JavaScript
Leonardo Borges
 
How prototype works in java script?
How prototype works in java script?How prototype works in java script?
How prototype works in java script?
InnovationM
 
Javascript
JavascriptJavascript
Javascript
Aditya Gaur
 
Javascript Object Oriented Programming
Javascript Object Oriented ProgrammingJavascript Object Oriented Programming
Javascript Object Oriented Programming
Bunlong Van
 
JavaScript Essentials
JavaScript EssentialsJavaScript Essentials
JavaScript Essentials
Triphon Statkov
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
relay12
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
Manikanda kumar
 
JavaScript - Programming Languages course
JavaScript - Programming Languages course JavaScript - Programming Languages course
JavaScript - Programming Languages course
yoavrubin
 
JS Level Up: Prototypes
JS Level Up: PrototypesJS Level Up: Prototypes
JS Level Up: Prototypes
Vernon Kesner
 
Learn JS concepts by implementing jQuery
Learn JS concepts by implementing jQueryLearn JS concepts by implementing jQuery
Learn JS concepts by implementing jQuery
Wingify Engineering
 
Javascript talk
Javascript talkJavascript talk
Javascript talk
Suresh Jayanty
 
Javascript closures
Javascript closures Javascript closures
Javascript closures
VNG
 
Javascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big PictureJavascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big Picture
Manish Jangir
 
Coding using jscript test complete
Coding using jscript test completeCoding using jscript test complete
Coding using jscript test complete
Viresh Doshi
 
JavsScript OOP
JavsScript OOPJavsScript OOP
JavsScript OOP
LearningTech
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
LearningTech
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
Doeun KOCH
 
Module 10-Introduction to OOP.pptx
Module 10-Introduction to OOP.pptxModule 10-Introduction to OOP.pptx
Module 10-Introduction to OOP.pptx
ssuserec53e73
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
Julie Iskander
 

Similar to Prototype 120102020133-phpapp02 (20)

Introduction to javascript and yoolkui
Introduction to javascript and yoolkuiIntroduction to javascript and yoolkui
Introduction to javascript and yoolkui
 
The many facets of code reuse in JavaScript
The many facets of code reuse in JavaScriptThe many facets of code reuse in JavaScript
The many facets of code reuse in JavaScript
 
How prototype works in java script?
How prototype works in java script?How prototype works in java script?
How prototype works in java script?
 
Javascript
JavascriptJavascript
Javascript
 
Javascript Object Oriented Programming
Javascript Object Oriented ProgrammingJavascript Object Oriented Programming
Javascript Object Oriented Programming
 
JavaScript Essentials
JavaScript EssentialsJavaScript Essentials
JavaScript Essentials
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
JavaScript - Programming Languages course
JavaScript - Programming Languages course JavaScript - Programming Languages course
JavaScript - Programming Languages course
 
JS Level Up: Prototypes
JS Level Up: PrototypesJS Level Up: Prototypes
JS Level Up: Prototypes
 
Learn JS concepts by implementing jQuery
Learn JS concepts by implementing jQueryLearn JS concepts by implementing jQuery
Learn JS concepts by implementing jQuery
 
Javascript talk
Javascript talkJavascript talk
Javascript talk
 
Javascript closures
Javascript closures Javascript closures
Javascript closures
 
Javascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big PictureJavascript Prototypal Inheritance - Big Picture
Javascript Prototypal Inheritance - Big Picture
 
Coding using jscript test complete
Coding using jscript test completeCoding using jscript test complete
Coding using jscript test complete
 
JavsScript OOP
JavsScript OOPJavsScript OOP
JavsScript OOP
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
 
Module 10-Introduction to OOP.pptx
Module 10-Introduction to OOP.pptxModule 10-Introduction to OOP.pptx
Module 10-Introduction to OOP.pptx
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 

More from plutoone TestTwo

Presentation1.PPTX
Presentation1.PPTXPresentation1.PPTX
Presentation1.PPTX
plutoone TestTwo
 
Effective_presentation.ppt
Effective_presentation.pptEffective_presentation.ppt
Effective_presentation.ppt
plutoone TestTwo
 
Effective_presentation.ppt
Effective_presentation.pptEffective_presentation.ppt
Effective_presentation.ppt
plutoone TestTwo
 
Effective_presentation.ppt
Effective_presentation.pptEffective_presentation.ppt
Effective_presentation.ppt
plutoone TestTwo
 
from app
from appfrom app
example.pdf
example.pdfexample.pdf
example.pdf
plutoone TestTwo
 
7.2edited
7.2edited7.2edited
7.2edited
plutoone TestTwo
 
hello plutoone
hello plutoonehello plutoone
hello plutoone
plutoone TestTwo
 
plutoone channel
plutoone channelplutoone channel
plutoone channel
plutoone TestTwo
 
Document.docx.docx
Document.docx.docxDocument.docx.docx
Document.docx.docx
plutoone TestTwo
 
format.txt.txt
format.txt.txtformat.txt.txt
format.txt.txt
plutoone TestTwo
 
Presentation1.PPTX
Presentation1.PPTXPresentation1.PPTX
Presentation1.PPTX
plutoone TestTwo
 
Sample.ppt
Sample.pptSample.ppt
Sample.ppt
plutoone TestTwo
 
newdocument.txt
newdocument.txtnewdocument.txt
newdocument.txt
plutoone TestTwo
 
NetworkSecurity.ppt
NetworkSecurity.pptNetworkSecurity.ppt
NetworkSecurity.ppt
plutoone TestTwo
 
Presentation1.PPTX
Presentation1.PPTXPresentation1.PPTX
Presentation1.PPTX
plutoone TestTwo
 
another
anotheranother
All - Edited with description
All - Edited with descriptionAll - Edited with description
All - Edited with description
plutoone TestTwo
 
Allow downloads
Allow downloadsAllow downloads
Allow downloads
plutoone TestTwo
 
new widget
new widgetnew widget
new widget
plutoone TestTwo
 

More from plutoone TestTwo (20)

Presentation1.PPTX
Presentation1.PPTXPresentation1.PPTX
Presentation1.PPTX
 
Effective_presentation.ppt
Effective_presentation.pptEffective_presentation.ppt
Effective_presentation.ppt
 
Effective_presentation.ppt
Effective_presentation.pptEffective_presentation.ppt
Effective_presentation.ppt
 
Effective_presentation.ppt
Effective_presentation.pptEffective_presentation.ppt
Effective_presentation.ppt
 
from app
from appfrom app
from app
 
example.pdf
example.pdfexample.pdf
example.pdf
 
7.2edited
7.2edited7.2edited
7.2edited
 
hello plutoone
hello plutoonehello plutoone
hello plutoone
 
plutoone channel
plutoone channelplutoone channel
plutoone channel
 
Document.docx.docx
Document.docx.docxDocument.docx.docx
Document.docx.docx
 
format.txt.txt
format.txt.txtformat.txt.txt
format.txt.txt
 
Presentation1.PPTX
Presentation1.PPTXPresentation1.PPTX
Presentation1.PPTX
 
Sample.ppt
Sample.pptSample.ppt
Sample.ppt
 
newdocument.txt
newdocument.txtnewdocument.txt
newdocument.txt
 
NetworkSecurity.ppt
NetworkSecurity.pptNetworkSecurity.ppt
NetworkSecurity.ppt
 
Presentation1.PPTX
Presentation1.PPTXPresentation1.PPTX
Presentation1.PPTX
 
another
anotheranother
another
 
All - Edited with description
All - Edited with descriptionAll - Edited with description
All - Edited with description
 
Allow downloads
Allow downloadsAllow downloads
Allow downloads
 
new widget
new widgetnew widget
new widget
 

Recently uploaded

Registered-Establishment-List-in-Uttarakhand-pdf.pdf
Registered-Establishment-List-in-Uttarakhand-pdf.pdfRegistered-Establishment-List-in-Uttarakhand-pdf.pdf
Registered-Establishment-List-in-Uttarakhand-pdf.pdf
dazzjoker
 
Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian Matka
Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian MatkaDpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian Matka
Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian Matka
➒➌➎➏➑➐➋➑➐➐Dpboss Matka Guessing Satta Matka Kalyan Chart Indian Matka
 
Adani Group's Active Interest In Increasing Its Presence in the Cement Manufa...
Adani Group's Active Interest In Increasing Its Presence in the Cement Manufa...Adani Group's Active Interest In Increasing Its Presence in the Cement Manufa...
Adani Group's Active Interest In Increasing Its Presence in the Cement Manufa...
Adani case
 
Pro Tips for Effortless Contract Management
Pro Tips for Effortless Contract ManagementPro Tips for Effortless Contract Management
Pro Tips for Effortless Contract Management
Eternity Paralegal Services
 
Best Competitive Marble Pricing in Dubai - ☎ 9928909666
Best Competitive Marble Pricing in Dubai - ☎ 9928909666Best Competitive Marble Pricing in Dubai - ☎ 9928909666
Best Competitive Marble Pricing in Dubai - ☎ 9928909666
Stone Art Hub
 
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan ChartSatta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results
 
deft. 2024 pricing guide for onboarding
deft.  2024 pricing guide for onboardingdeft.  2024 pricing guide for onboarding
deft. 2024 pricing guide for onboarding
hello960827
 
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan ChartSatta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results
 
High-Quality IPTV Monthly Subscription for $15
High-Quality IPTV Monthly Subscription for $15High-Quality IPTV Monthly Subscription for $15
High-Quality IPTV Monthly Subscription for $15
advik4387
 
IMG_20240615_091110.pdf dpboss guessing
IMG_20240615_091110.pdf dpboss  guessingIMG_20240615_091110.pdf dpboss  guessing
Enhancing Adoption of AI in Agri-food: Introduction
Enhancing Adoption of AI in Agri-food: IntroductionEnhancing Adoption of AI in Agri-food: Introduction
Enhancing Adoption of AI in Agri-food: Introduction
Cor Verdouw
 
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan ChartSatta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results
 
一比一原版(QMUE毕业证书)英国爱丁堡玛格丽特女王大学毕业证文凭如何办理
一比一原版(QMUE毕业证书)英国爱丁堡玛格丽特女王大学毕业证文凭如何办理一比一原版(QMUE毕业证书)英国爱丁堡玛格丽特女王大学毕业证文凭如何办理
一比一原版(QMUE毕业证书)英国爱丁堡玛格丽特女王大学毕业证文凭如何办理
taqyea
 
8328958814KALYAN MATKA | MATKA RESULT | KALYAN
8328958814KALYAN MATKA | MATKA RESULT | KALYAN8328958814KALYAN MATKA | MATKA RESULT | KALYAN
8328958814KALYAN MATKA | MATKA RESULT | KALYAN
➑➌➋➑➒➎➑➑➊➍
 
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan ChartSatta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results
 
1Q24_HYUNDAI CAPITAL SERVICES INC. AND SUBSIDIARIES
1Q24_HYUNDAI CAPITAL SERVICES INC. AND SUBSIDIARIES1Q24_HYUNDAI CAPITAL SERVICES INC. AND SUBSIDIARIES
1Q24_HYUNDAI CAPITAL SERVICES INC. AND SUBSIDIARIES
irhcs
 
Call 8867766396 Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian M...
Call 8867766396 Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian M...Call 8867766396 Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian M...
Call 8867766396 Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian M...
dpbossdpboss69
 
Pitch Deck Teardown: Kinnect's $250k Angel deck
Pitch Deck Teardown: Kinnect's $250k Angel deckPitch Deck Teardown: Kinnect's $250k Angel deck
Pitch Deck Teardown: Kinnect's $250k Angel deck
HajeJanKamps
 
CULR Spring 2024 Journal.pdf testing for duke
CULR Spring 2024 Journal.pdf testing for dukeCULR Spring 2024 Journal.pdf testing for duke
CULR Spring 2024 Journal.pdf testing for duke
ZevinAttisha
 
欧洲杯赌球-欧洲杯赌球买球官方官网-欧洲杯赌球比赛投注官网|【​网址​🎉ac55.net🎉​】
欧洲杯赌球-欧洲杯赌球买球官方官网-欧洲杯赌球比赛投注官网|【​网址​🎉ac55.net🎉​】欧洲杯赌球-欧洲杯赌球买球官方官网-欧洲杯赌球比赛投注官网|【​网址​🎉ac55.net🎉​】
欧洲杯赌球-欧洲杯赌球买球官方官网-欧洲杯赌球比赛投注官网|【​网址​🎉ac55.net🎉​】
valvereliz227
 

Recently uploaded (20)

Registered-Establishment-List-in-Uttarakhand-pdf.pdf
Registered-Establishment-List-in-Uttarakhand-pdf.pdfRegistered-Establishment-List-in-Uttarakhand-pdf.pdf
Registered-Establishment-List-in-Uttarakhand-pdf.pdf
 
Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian Matka
Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian MatkaDpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian Matka
Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian Matka
 
Adani Group's Active Interest In Increasing Its Presence in the Cement Manufa...
Adani Group's Active Interest In Increasing Its Presence in the Cement Manufa...Adani Group's Active Interest In Increasing Its Presence in the Cement Manufa...
Adani Group's Active Interest In Increasing Its Presence in the Cement Manufa...
 
Pro Tips for Effortless Contract Management
Pro Tips for Effortless Contract ManagementPro Tips for Effortless Contract Management
Pro Tips for Effortless Contract Management
 
Best Competitive Marble Pricing in Dubai - ☎ 9928909666
Best Competitive Marble Pricing in Dubai - ☎ 9928909666Best Competitive Marble Pricing in Dubai - ☎ 9928909666
Best Competitive Marble Pricing in Dubai - ☎ 9928909666
 
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan ChartSatta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
 
deft. 2024 pricing guide for onboarding
deft.  2024 pricing guide for onboardingdeft.  2024 pricing guide for onboarding
deft. 2024 pricing guide for onboarding
 
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan ChartSatta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
 
High-Quality IPTV Monthly Subscription for $15
High-Quality IPTV Monthly Subscription for $15High-Quality IPTV Monthly Subscription for $15
High-Quality IPTV Monthly Subscription for $15
 
IMG_20240615_091110.pdf dpboss guessing
IMG_20240615_091110.pdf dpboss  guessingIMG_20240615_091110.pdf dpboss  guessing
IMG_20240615_091110.pdf dpboss guessing
 
Enhancing Adoption of AI in Agri-food: Introduction
Enhancing Adoption of AI in Agri-food: IntroductionEnhancing Adoption of AI in Agri-food: Introduction
Enhancing Adoption of AI in Agri-food: Introduction
 
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan ChartSatta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
 
一比一原版(QMUE毕业证书)英国爱丁堡玛格丽特女王大学毕业证文凭如何办理
一比一原版(QMUE毕业证书)英国爱丁堡玛格丽特女王大学毕业证文凭如何办理一比一原版(QMUE毕业证书)英国爱丁堡玛格丽特女王大学毕业证文凭如何办理
一比一原版(QMUE毕业证书)英国爱丁堡玛格丽特女王大学毕业证文凭如何办理
 
8328958814KALYAN MATKA | MATKA RESULT | KALYAN
8328958814KALYAN MATKA | MATKA RESULT | KALYAN8328958814KALYAN MATKA | MATKA RESULT | KALYAN
8328958814KALYAN MATKA | MATKA RESULT | KALYAN
 
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan ChartSatta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
 
1Q24_HYUNDAI CAPITAL SERVICES INC. AND SUBSIDIARIES
1Q24_HYUNDAI CAPITAL SERVICES INC. AND SUBSIDIARIES1Q24_HYUNDAI CAPITAL SERVICES INC. AND SUBSIDIARIES
1Q24_HYUNDAI CAPITAL SERVICES INC. AND SUBSIDIARIES
 
Call 8867766396 Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian M...
Call 8867766396 Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian M...Call 8867766396 Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian M...
Call 8867766396 Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian M...
 
Pitch Deck Teardown: Kinnect's $250k Angel deck
Pitch Deck Teardown: Kinnect's $250k Angel deckPitch Deck Teardown: Kinnect's $250k Angel deck
Pitch Deck Teardown: Kinnect's $250k Angel deck
 
CULR Spring 2024 Journal.pdf testing for duke
CULR Spring 2024 Journal.pdf testing for dukeCULR Spring 2024 Journal.pdf testing for duke
CULR Spring 2024 Journal.pdf testing for duke
 
欧洲杯赌球-欧洲杯赌球买球官方官网-欧洲杯赌球比赛投注官网|【​网址​🎉ac55.net🎉​】
欧洲杯赌球-欧洲杯赌球买球官方官网-欧洲杯赌球比赛投注官网|【​网址​🎉ac55.net🎉​】欧洲杯赌球-欧洲杯赌球买球官方官网-欧洲杯赌球比赛投注官网|【​网址​🎉ac55.net🎉​】
欧洲杯赌球-欧洲杯赌球买球官方官网-欧洲杯赌球比赛投注官网|【​网址​🎉ac55.net🎉​】
 

Prototype 120102020133-phpapp02

  • 3.  Creating a hierarchy  Code reuse
  • 4. Classical inheritance Objects are instances of classes A Class inherits from other class
  • 5. Prototypal inheritance A prototypal language is a class less object oriented language.  OOP without classes – now that’s weird Here Objects inherit from objects  What could be more object oriented than this!  Code reuse done via cloning
  • 6. How do we do this?
  • 7. prototype A prototype is an object used to implement structure, state, and behaviour inheritance in ECMAScript.
  • 8. So, what kind of objects contain the prototype object?
  • 9. Each and every object (Except the Object.prototype)
  • 10. What !But when I do { }.prototype, I get null :-/
  • 11. So what is prototype actually? The true prototype of an object is held by the internal [[Prototype]] property. This is represented as __proto__ in some of the browsers like firefox. __proto__ oldObjectnewObject
  • 12. Accessing the prototype Most browsers support the non standard accessor __proto__ . ECMA 5 introduces the standard accessor Object.getPrototypeOf(object) Use object constructor. object.constructor.prototype
  • 13. Example var baseObject = { firstMethod: function () {alert(“first method");}, secondMethod: function () {alert(“second method");} }; var extendedObject = {}; extendedObject.thirdMethod = function () {alert(“third method")}; extendedObject.__proto__ = baseObject; extendedObject.firstMethod(); extendedObject.thirdMethod(); firstMethod secondMethod __proto__ thirdMethod __proto__ baseObjectextendedObject
  • 14. Prototype chaining When an object is asked to evaluate property foo, JavaScript walks the prototype chain (starting with object a itself), checking each link in the chain for the presence of property foo. If and when foo is found it is returned, otherwise undefined is returned.
  • 15. var baseObject = { name: "FooBarBaz", getModifiedString : function(){ return "Hello " + this.name; } }; var extendedObject = { age : 10 }; extendedObject.__proto__ = baseObject; extendedObject.getModifiedString(); extendedObject.toString(); name getModifiedString __proto__ age __proto__ baseObject extendedObject toString __proto__ Object.prototype null
  • 16. OK, So what was the prototype we were talking about in the last session?
  • 17. Prototype property in functions var newClass = function (){ var privateVal = 10; this.publicVal = 20; } newClass.prototype.sharedVal = 30; what's this?  The functions in JavaScript are objects and they contain methods and properties.  One of property of the function objects is prototype.  A function’s prototype property is the object that will be assigned as the prototype ([[Prototype]] ) to all instances created when this function is used as a constructor.
  • 18. examples //function will never be a constructor but it has a prototype property anyway Math.max.prototype; //[object Object] //function intended to be a constructor has a prototype too var A = function(name) { this.name = name; } A.prototype; //[object Object] //Math is not a function so no prototype property Math.prototype; //null  Every function has a prototype property, and the objects which are not function don’t have the prototype property.
  • 19. examples function Foo(name){ this.name = name; } Foo.prototype.getName = function(){ return this.name; } var obj = new Foo("bar"); obj.getName(); Foo prototype __proto__ constructor getName obj name __proto__ Function.prototype
  • 20. Examples (augmentation) function Foo(name){ this.name = name; } Foo.prototype.getName = function(){ return this.name; }; var obj = new Foo("bar"); obj.getName(); //bar Foo.prototype.getFullName = function(){ return "Foo" + this.name; }; obj.getFullName();// Foobar  Note that the prototype is "live". Objects are passed by reference in JavaScript, and therefore the prototype is not copied with every new object instance.  It means that prototype property can be changed at any time and all the instances will reflect the change.
  • 21. A catch function Foo(name){ this.name = name; } Foo.prototype.getName = function(){ return this.name; }; var obj = new Foo("bar"); obj.getName(); //bar Foo.prototype = { getFullName : function (){ return "FOO" + this.name; } }; obj.getFullName();// ERROR obj.getName(); //bar var obj2 = new Foo("baz"); obj2.getFullName(); //FOObaz  If the prototype property is completely replaced the object still points to the original prototype ([[Prototype]] )
  • 22. Object.create = function (o) { function F() {} F.prototype = o; return new F(); };  Creates a new object with the specified prototype object and properties  Introduced in ECMAscript 5. Object.create
  • 23. var func = function(){ alert(this); this.aVar =10; } var aVar = func();  The new keyword.  If we forget the new keyword, “this” is bounded to global object.  Also gives an impression of classical inheritance  Deprecated __proto__ Object.create. Why ?
  • 24.  Douglas Crockford’s video lecture on Advanced javascript  Mozilla developer network References