Here i have a code which uses getter and setter to define and fetch a property value.I created an object using a object constructor.I passed the object in a for...in loop.Also used getOwnPropertyNames() method on the object.Here are the results
"fullName" property is accessible in for...in loop
"fullName" is not visible in getOwnPropertyNames() method.That means it is
not a own property
Here i have two basic question.What is an own property? If "fullName" is not a own property then what type of property it is ?
function Name(first, last) {
this.first = first;
this.last = last;
}
Name.prototype = {
get fullName() {
return this.first + " " + this.last;
},
set fullName(name) {
var names = name.split(" ");
this.first = names[0];
this.last = names[1];
}
};
var obj=new Name('al','zami');
for(var i in obj){
console.log(i); // fullName is here
}
console.log(Object.getOwnPropertyNames(obj)); // fullName is not here