Let we have the following JS code:
function doThis(){
myKeys=[];
var span= document.createElement("span");
var parent=document.getElementById("parent");
var child=document.getElementById("child");
var submit=document.getElementById("submit");
child.insertBefore(span,submit.nextSibling);
Person.prototype={pr: "pr"};
var p= new Person("Ivan", "Ivanov");
myKeys.push(getAllKeyValuePair(Person));
span.innerHTML=myKeys;
}
function getAllKeyValuePair(obj){
var str="";
for(var key in obj){
try{
str=str+"{"+key+", "+obj[key]+"}";
}
catch(e){
console.log(key);
}
}
return str;
}
function Person(name,surname){
this.name=name;
this.surname=surname;
}
JSFIDDLE
we declare prototype property of Person constructor function at the line
Person.prototype={pr: "pr"};
But when I'm trying to print all property of Person I'm excepted that we have at least prototype properties which indicate to {pr: "pr"} object. But if we replace line
myKeys.push(getAllKeyValuePair(Person));
to the line
myKeys.push(getAllKeyValuePair(Person.prototype));
we can see the {pr, "pr"}.
I don't understand this, please explain me why it's occurring?