OneCompiler

Adding Properties and Methods to Object constructors

139

function Person(first,last,age,eyeColor){
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyeColor;
}
Person.nationality = "English"
Person.prototype.nationality = "Indian"
Person.prototype.fullName = function(){
return this.firstName + this.lastName
}
const mySelf = new Person("phanee","g",24,"golden brown")
console.log(mySelf.nationality,mySelf.fullName())