SlideShare a Scribd company logo
JAVASCRIPT PROTOTYPE OBJECT
JAVASCRIPT PROTOTYPE OBJECT
JavaScript is a prototype-based language that facilitates
the objects to acquire properties and features from one
another. Here, each object contains a prototype object.
In JavaScript, whenever a function is created the prototype
property is added to that function automatically. This
property is a prototype object that holds a constructor
property.
JAVASCRIPT PROTOTYPE OBJECT
Syntax:
ClassName.prototype.methodName
What is the requirement of a
prototype object?
Whenever an object is created in JavaScript, its
corresponding functions are loaded into memory. So, a
new copy of the function is created on each object
creation.
In a prototype-based approach, all the objects share the
same function. This ignores the requirement of creating a
new copy of function for each object. Thus, the functions
are loaded once into the memory.
JAVASCRIPT PROTOTYPE OBJECT
Prototype Chaining
In JavaScript, each object contains a prototype object that
acquires properties and methods from it. Again an object's
prototype object may contain a prototype object that also
acquires properties and methods, and so on. It can be
seen as prototype chaining.
JavaScript Prototype Object Example
2
Let's see an example to add a new
method to the constructor function.
<!DOCTYPE html>
<html>
<body>
<script>
function Employee(firstName,lastName)
{
this.firstName=firstName;
this.lastName=lastName;
}
Employee.prototype.company="Javatpoint"
var employee1=new Employee("Martin","Roy");
var employee2=new Employee("Duke",
"William");
document.writeln(employee1.firstName+"
"+employee1.lastName+"
"+employee1.company+"<br>");
document.writeln(employee2.firstName+"
"+employee2.lastName+" "+employee2.company);
</script>
</body>
</html>
JavaScript Constructor Method
A JavaScript constructor
method is a special type of
method which is used to
initialize and create an
object. It is called when
memory is allocated for an
object.
Points to remember:
o The constructor
keyword is used
to declare a
constructor
method.
o The class can
contain one
constructor
method only.
o JavaScript allows
us to use parent
class constructor
through super
keyword.
Constructor Method Example
Let's see a simple example of a constructor
method.
<!DOCTYPE html>
<html>
<body>
<script>
class Employee {
constructor() {
this.id=101;
this.name = "Martin Roy";
}
}
var emp = new Employee();
document.writeln(emp.id+" "+emp.name);
</script>
</body>
</html>
Constructor Method Example: super keyword
The super keyword is used to call the parent class
constructor. Let's see an example.
<!DOCTYPE html>
<html>
<body>
<script>
class CompanyName
{
constructor()
{
this.company="trizymartzy";
}
}
class Employee extends CompanyName {
constructor(id,name) {
super();
this.id=id;
this.name=name;
}
}
var emp = new Employee(1,"John");
document.writeln(emp.id+" "+emp.name+"
"+emp.company);
</script>
</body>
</html>
What have you learned?
Activity 01: Perform the
codes for:
1.Prototype object;
2.Constructor method;and
3. Super keyword
Activity 1: Rubrics
Points Description
10 The student successfully executes the program without guidance or supervision.
9 The student successfully executes the program with very little supervision and
guidance.
8 The student successfully executes the program with moderate supervision andguidance.
7 The student was not able to execute the program but shows eagerness to accomplishthe
activity.
5 The student was not able to execute the program due to lack of interest in the activity.
Thank You!

More Related Content

PPTX
Object oriented javascript
Usman Mehmood
 
PDF
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
PDF
Prototype 120102020133-phpapp02
plutoone TestTwo
 
PPT
Advanced JavaScript
Fu Cheng
 
PDF
Prototype
Aditya Gaur
 
PPTX
Javascript Objects Deep Dive
Manish Jangir
 
PDF
JS Level Up: Prototypes
Vernon Kesner
 
PPTX
Journey of a C# developer into Javascript
Massimo Franciosa
 
Object oriented javascript
Usman Mehmood
 
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
Prototype 120102020133-phpapp02
plutoone TestTwo
 
Advanced JavaScript
Fu Cheng
 
Prototype
Aditya Gaur
 
Javascript Objects Deep Dive
Manish Jangir
 
JS Level Up: Prototypes
Vernon Kesner
 
Journey of a C# developer into Javascript
Massimo Franciosa
 

Similar to Prototype Object.pptx (20)

PDF
OOPS JavaScript Interview Questions PDF By ScholarHat
Scholarhat
 
PDF
JavaScript Essentials
Triphon Statkov
 
PPTX
Object Oriented Javascript part2
Usman Mehmood
 
PPTX
Javascript Prototypal Inheritance - Big Picture
Manish Jangir
 
KEY
Javascript tid-bits
David Atchley
 
PPTX
JavaScript OOPS Implimentation
Usman Mehmood
 
PPTX
Function-and-prototype defined classes in JavaScript
Hong Langford
 
PPT
Java script unleashed
Dibyendu Tiwary
 
PPT
Advanced Javascript
Manikanda kumar
 
PPT
Advanced Javascript
Adieu
 
PPT
Advanced Javascript
relay12
 
PPT
JavaScript - Programming Languages course
yoavrubin
 
PDF
JavaScript Core
François Sarradin
 
PPTX
WEB222-lecture-4.pptx
RohitSharma318779
 
PPTX
Oojs 1.1
Rodica Dada
 
PPTX
Ajaxworld
deannalagason
 
PPT
JavaScript In Object Oriented Way
Borey Lim
 
PPT
Javascript Object Oriented Programming
Bunlong Van
 
PPTX
JavsScript OOP
LearningTech
 
PDF
Object Oriented Programming in JavaScript
zand3rs
 
OOPS JavaScript Interview Questions PDF By ScholarHat
Scholarhat
 
JavaScript Essentials
Triphon Statkov
 
Object Oriented Javascript part2
Usman Mehmood
 
Javascript Prototypal Inheritance - Big Picture
Manish Jangir
 
Javascript tid-bits
David Atchley
 
JavaScript OOPS Implimentation
Usman Mehmood
 
Function-and-prototype defined classes in JavaScript
Hong Langford
 
Java script unleashed
Dibyendu Tiwary
 
Advanced Javascript
Manikanda kumar
 
Advanced Javascript
Adieu
 
Advanced Javascript
relay12
 
JavaScript - Programming Languages course
yoavrubin
 
JavaScript Core
François Sarradin
 
WEB222-lecture-4.pptx
RohitSharma318779
 
Oojs 1.1
Rodica Dada
 
Ajaxworld
deannalagason
 
JavaScript In Object Oriented Way
Borey Lim
 
Javascript Object Oriented Programming
Bunlong Van
 
JavsScript OOP
LearningTech
 
Object Oriented Programming in JavaScript
zand3rs
 
Ad

More from Steins18 (18)

PPTX
morse code follow up activity for grade 10.pptx
Steins18
 
PPTX
morse code follow up activity for grade 10.pptx
Steins18
 
PPTX
morse code for grade 10 high schoollearners.pptx
Steins18
 
PPTX
orthographic projection for engineering.pptx
Steins18
 
PPTX
Shading lecture for learners in highschool.pptx
Steins18
 
PPTX
Enum in a Switch Statement learning material.pptx
Steins18
 
PPTX
PseudoCoding-enrichment activity for learners02.pptx
Steins18
 
PPTX
PseudoCoding-enrichment activity for students.pptx
Steins18
 
PPTX
powerpoint workstation intended for learners.pptx
Steins18
 
PPTX
POWERPOINT learning materials for students.pptx
Steins18
 
PPTX
computer programming: an introduction.pptx
Steins18
 
PPTX
introduction program logic Formulation.pptx
Steins18
 
PPTX
creating html using notepad-learning material
Steins18
 
PPTX
Visual BAsic Softwares intended for ICT students
Steins18
 
PPTX
Cookie Attribute.pptx
Steins18
 
PPTX
Defining method in JavaScript object.pptx
Steins18
 
PPTX
HTML Attributes.pptx
Steins18
 
PPTX
JavaScript number object.pptx
Steins18
 
morse code follow up activity for grade 10.pptx
Steins18
 
morse code follow up activity for grade 10.pptx
Steins18
 
morse code for grade 10 high schoollearners.pptx
Steins18
 
orthographic projection for engineering.pptx
Steins18
 
Shading lecture for learners in highschool.pptx
Steins18
 
Enum in a Switch Statement learning material.pptx
Steins18
 
PseudoCoding-enrichment activity for learners02.pptx
Steins18
 
PseudoCoding-enrichment activity for students.pptx
Steins18
 
powerpoint workstation intended for learners.pptx
Steins18
 
POWERPOINT learning materials for students.pptx
Steins18
 
computer programming: an introduction.pptx
Steins18
 
introduction program logic Formulation.pptx
Steins18
 
creating html using notepad-learning material
Steins18
 
Visual BAsic Softwares intended for ICT students
Steins18
 
Cookie Attribute.pptx
Steins18
 
Defining method in JavaScript object.pptx
Steins18
 
HTML Attributes.pptx
Steins18
 
JavaScript number object.pptx
Steins18
 
Ad

Recently uploaded (20)

PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PPTX
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PDF
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
PPTX
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
Basics and rules of probability with real-life uses
ravatkaran694
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 

Prototype Object.pptx

  • 2. JAVASCRIPT PROTOTYPE OBJECT JavaScript is a prototype-based language that facilitates the objects to acquire properties and features from one another. Here, each object contains a prototype object. In JavaScript, whenever a function is created the prototype property is added to that function automatically. This property is a prototype object that holds a constructor property.
  • 3. JAVASCRIPT PROTOTYPE OBJECT Syntax: ClassName.prototype.methodName What is the requirement of a prototype object? Whenever an object is created in JavaScript, its corresponding functions are loaded into memory. So, a new copy of the function is created on each object creation. In a prototype-based approach, all the objects share the same function. This ignores the requirement of creating a new copy of function for each object. Thus, the functions are loaded once into the memory.
  • 4. JAVASCRIPT PROTOTYPE OBJECT Prototype Chaining In JavaScript, each object contains a prototype object that acquires properties and methods from it. Again an object's prototype object may contain a prototype object that also acquires properties and methods, and so on. It can be seen as prototype chaining.
  • 5. JavaScript Prototype Object Example 2 Let's see an example to add a new method to the constructor function. <!DOCTYPE html> <html> <body> <script> function Employee(firstName,lastName) { this.firstName=firstName; this.lastName=lastName; } Employee.prototype.company="Javatpoint" var employee1=new Employee("Martin","Roy"); var employee2=new Employee("Duke", "William"); document.writeln(employee1.firstName+" "+employee1.lastName+" "+employee1.company+"<br>"); document.writeln(employee2.firstName+" "+employee2.lastName+" "+employee2.company); </script> </body> </html>
  • 6. JavaScript Constructor Method A JavaScript constructor method is a special type of method which is used to initialize and create an object. It is called when memory is allocated for an object. Points to remember: o The constructor keyword is used to declare a constructor method. o The class can contain one constructor method only. o JavaScript allows us to use parent class constructor through super keyword.
  • 7. Constructor Method Example Let's see a simple example of a constructor method. <!DOCTYPE html> <html> <body> <script> class Employee { constructor() { this.id=101; this.name = "Martin Roy"; } } var emp = new Employee(); document.writeln(emp.id+" "+emp.name); </script> </body> </html>
  • 8. Constructor Method Example: super keyword The super keyword is used to call the parent class constructor. Let's see an example. <!DOCTYPE html> <html> <body> <script> class CompanyName { constructor() { this.company="trizymartzy"; } } class Employee extends CompanyName { constructor(id,name) { super(); this.id=id; this.name=name; } } var emp = new Employee(1,"John"); document.writeln(emp.id+" "+emp.name+" "+emp.company); </script> </body> </html>
  • 9. What have you learned?
  • 10. Activity 01: Perform the codes for: 1.Prototype object; 2.Constructor method;and 3. Super keyword Activity 1: Rubrics Points Description 10 The student successfully executes the program without guidance or supervision. 9 The student successfully executes the program with very little supervision and guidance. 8 The student successfully executes the program with moderate supervision andguidance. 7 The student was not able to execute the program but shows eagerness to accomplishthe activity. 5 The student was not able to execute the program due to lack of interest in the activity.