function Human(){
this.job = 'code'
}
//Human.prototype = {feeds: 'Pizza'};
var developer = new Human();
console.log(developer.constructor);
Above console logs
function Human() {
this.job = 'code';
}
When i uncomment the line Human.prototype = {feeds: 'Pizza'}; it console logs
function Object() {
[native code]
}
Why setting prototype on constructor function, affects who is the constructor on object created by the constructor?
Another example:
function LivingBeing() {
breathes: 'air';
}
function Human(){
feeds: 'Pizza';
}
//Human.prototype = new LivingBeing();
var developer = new Human();
console.log(developer.constructor);
With commented like it says constructor is Human, when uncommented it says LivingBeing. Why constructor traverses further when something valid found on prototype?
I thought to add one more level to this
function AThing(){
this.say = function(){return 'I am thing';};
}
function LivingBeing() {
breathes: 'air';
}
LivingBeing.prototype = new AThing();
function Human(){
feeds: 'Pizza';
}
Human.prototype = new LivingBeing();
var developer = new Human();
console.log(developer.constructor);
Now its says developer's constructor is AThing. Can i say constructor goes as far as possible in the prototype chain?