📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.
🎓 Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.
▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube
Prototype Pattern Overview
For example, the below diagram shows a prototype of different cars:
Prototype Pattern Example
// using Object.create Method
var Employee = {
firstName : 'Ramesh',
lastName : 'Fadatare',
emailId : 'ramesh@gmail.com',
age : 29,
getFullName : function (){
return user.firstName + " " + user.lastName;
}
}
var employee1 = Object.create(Employee);
// access new object properties
console.log('firstName :', employee1.firstName);
console.log('lastName :', employee1.lastName);
console.log('emailId :', employee1.emailId);
console.log('age :', employee1.age);
firstName : Ramesh
lastName : Fadatare
emailId : ramesh@gmail.com
age : 29
// using Object.create Method
var Employee = {
firstName : 'Ramesh',
lastName : 'Fadatare',
getFullName : function (){
return user.firstName + " " + user.lastName;
}
}
var employee1 = Object.create(Employee,{
"emailId": {
value: "ramesh@gmail.com",
// writable:false, configurable:false by default
enumerable: true
},
"age": {
value: 29,
enumerable: true
}
});
// access new object properties
console.log('firstName :', employee1.firstName);
console.log('lastName :', employee1.lastName);
console.log('emailId :', employee1.emailId);
console.log('age :', employee1.age);
firstName : Ramesh
lastName : Fadatare
emailId : ramesh@gmail.com
age : 29
Related JavaScript Design Patterns
- JavaScript Factory Pattern with Example //Popular
- JavaScript Builder Pattern Example //Popular
Comments
Post a Comment
Leave Comment