// prototypes in javascript, THey create new Methods to our constructor function
const EmployersInfo = function(name , salary , bonusPercentage){
this.name = name ;
this.salary = salary;
this.bonusPercentage = bonusPercentage;
}
// prototype for getting the employer credential
EmployersInfo.prototype.credentialInfo = function(){
return `${this.name} Has a base salary of ${this.salary}`;
}
EmployersInfo.prototype.getBonus = function(){
let bonusAmount = (this.salary * (this.bonusPercentage));
return `${this.name} earned ${bonusAmount} Bonus`;
}
// let's first create the instance of employerInform
const employerInform = new EmployersInfo('kevin' , 12000 , 12);
// logging employerInform
console.log(employerInform);
// logging the credentials
console.log(employerInform.credentialInfo());
// logging the Bonus function
console.log(employerInform.getBonus());
2
Show 6 More Grepper Results