📘 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
JavaScript Builder Pattern Example
let User = function (firstName, lastName, email) {
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
}
let UserBuilder = function () {
let firstName;
let lastName;
let email;
return {
setFirstName: function (firstName) {
this.firstName = firstName;
return this;
},
setLastName: function (lastName) {
this.lastName = lastName;
return this;
},
setEmail: function (email) {
this.email = email;
return this;
},
info: function () {
return `${this.firstName} ${this.lastName}, ${this.email}`;
},
build: function () {
return new User(firstName, lastName, email);
}
};
};
var user = new UserBuilder().setFirstName('Ramesh').setLastName('Fadatare')
.setEmail('ramesh@gmail.com');
console.log(user.info());
Ramesh Fadatare, ramesh@gmail.com
Comments
Post a Comment
Leave Comment