Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// Example Of Constructor Function
function User(firstName, lastName, age) {
this.firstName = firstName
this.lastName = lastName
this.age = age
this.getDetails = function () {
console.log(`I am ${this.firstName} ${this.lastName}`)
// Creating a new person with 'new' keyword
const akash = new User('Akash', 'Rajvanshi', 22)
console.log(akash) // User { firstName: 'Akash', lastName: 'Rajvanshi', age: 22, getDetails: [λ] }
console.log(akash.getDetails()) // I am Akash Rajvanshi
// New User
const abha = new User('Abha', 'Rajvanshi', 58)
console.log(abha) // User { firstName: 'Abha', lastNam: 'Rajvanshi', age: 58, getDetails: [λ] }
console.log(abha.getDetails()) // I am Abha Rajvanshi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.