Difference between proto and prototype
Last Updated :
13 May, 2024
In this article, we will be going to cover the topic what is proto and prototypes, their syntax, examples, and what are differences exist between both, and how they differ and how they differ in different aspects.
Proto and prototype both are objects that help in whether creating an array, object, or function and provide access to those specific methods or objects directly without taking memory and even it will give access to its constructor and all the array methods like push, pop, etc.
Proto: It is an actual object that provides a way to inherit properties from JavaScript with the help of an object which is created with new. Every object with behavior associated has internal property [[prototype]].
Syntax:
Object.__proto__ = value
Example:
JavaScript
function Student(name,age) {
this.name = name;
this.age = age;
}
var stu1 = new Student("John", 50);
// Object have proto property
stu1
// Also if apply strict equal to check
// if both point at the same
// location then it will return true.
Student.prototype === stu1.__proto__
Output:
object have proto property
object and function refer to the same prototypePrototype: It is a special object which means it holds shared attributes and behaviors of instances. It is a way to inherit properties from javascript as it is available in every function declaration.
Syntax:
objectTypeName.prototype.SharedPropertyName=value;
Example:
JavaScript
// Constructor function
function Student(name, age) {
this.name = name;
this.age = age;
}
// Objects
var stu1 = new Student("gfg1", 25);
var stu2 = new Student("gfg2", 42);
// Prototype
Student.prototype.getName = function() { return this.name; }
// Function have property prototype
// Student
// Function call using object
stu1.getName();
// Constructor function
function Student(name, age) {
this.name = name;
this.age = age;
}
// Objects
var stu1 = new Student("gfg1", 25);
var stu2 = new Student("gfg2", 42);
// Prototype
Student.prototype.getName = function() { return this.name; }
// Function have property prototype
// Student
// function call using object
stu1.getName();
// Access prototype
Student.prototype
Output:
function have property prototype
function call using object
access prototype propertyDifference between proto and prototype:
Prototype
| proto
|
Prototypes is a simple way to share behavior and data between multiple objects access using .prototype | proto is also a way to share behavior and data between multiple objects access using __proto__ |
All the object constructors (function) have prototype properties. | All the objects have proto property. |
The prototype gives access to the prototype of function using function.
Syntax: (function.prototype)
| proto gives access to the prototype of the function using the object.
Syntax: (object.__proto__)
|
It is mostly used to resolve issues of memory wastage when creating an object in constructor mode then each object has separate behavior. | It is used in the lookup chain to resolve methods, constructors, etc. |
It is the property of the class. | It is the property of the instance of that class. |
The prototype property is set to function when it is declared. All the functions have a prototype property. | proto property that is set to an object when it is created using a new keyword. All objects behavior newly created have proto properties. |
It is introduced in EcmaScript 6. | It is introduced in ECMAScript 5. |
It is also called it as .prototype | It is also called dunder proto. |
It is mostly used in javaScript. | It is rarely used in JavaScript. |
Similar Reads
Difference between PROM and EPROM PROM (Programmable Read-Only Memory) is a type of ROM that is written only once. It was meant to fulfill the requirement of a group of ROMs which may contain a selected memory content. It's memory is written just the once and programmed electrically by the user at the time or when the initial chip f
2 min read
Difference between Project and Product A project refers to the series of steps involved in creating software before it becomes available to the market. Once the project is completed, the outcome is termed as a product. The primary goal of a project is to build this unique product, focusing on enhancing performance and ensuring it meets t
3 min read
Difference between Product and Process Product: In the context of software engineering, Product includes any software manufactured based on the customer's request. This can be a problem solving software or computer based system. It can also be said that this is the result of a project. Process: Process is a set of sequence steps that hav
2 min read
Difference between Program and Product A program is a set of instructions written by a programmer to perform a specific task on a computer. In contrast, a product is a complete software solution developed through a series of stages, known as the software development life cycle, to address a specific problem or need for an enterprise. Pro
3 min read
Difference between EPROM and EEPROM EPROM and EEPROM are types of ROM, which stands for Read-Only Memory. ROM is a kind of computer memory that you can only read from, not write to. This means once you put information in ROM, you can't change it. ROM keeps the information even when you turn off the computer. Before we compare EPROM an
6 min read
Difference between Prototype Model and RAD Model 1. Prototype Model : The prototype model is a software development life cycle model which is used when the customer is not known completely about how the end product should be and its requirements. So in this model, a prototype of the end product is first developed by the developers and then tested
2 min read