function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
this.getLastName = function() {
return this.lastName;
}
}
const firstPerson = new Person("Azizbek", "Ahmadjonov")
console.log(firstPerson.firstName);
console.log(firstPerson.getLastName());
Function Constructor ni Pythondagi OOP ga o'xshatish mumkin.
This yuqoridagi self bilan bir xil vazifani bajaradi!
this.firstName = firstName;
this.lastName = lastName;
this.getLastName = function() {
return this.lastName;
}
}
const firstPerson = new Person("Azizbek", "Ahmadjonov")
console.log(firstPerson.firstName);
console.log(firstPerson.getLastName());
Function Constructor ni Pythondagi OOP ga o'xshatish mumkin.
This yuqoridagi self bilan bir xil vazifani bajaradi!