Prototype make parameter to False, js

Tell us what’s happening:

why in prototype(numLegs) isn’t in beagle? (console.log(beagle))

hasOwnProperty found only first object ? parameter numLegs=False, why?

Your code so far


function Dog(name) {
this.name = name;
}

Dog.prototype.numLegs = 4;

let beagle = new Dog("Snoopy");

let ownProps = [];
let prototypeProps = [];

// Only change code below this line

for( let property in beagle){
if(beagle.hasOwnProperty(property)){
  ownProps.push(property);}
  else {
    prototypeProps.push(property);
  }
}



console.log(ownProps);
console.log(prototypeProps);

console.log(beagle);  //<---


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66.

Challenge: Iterate Over All Properties

Link to the challenge:

I’m no expert, but …

Because this is the constructor:

function Dog(name) {
  this.name = name;
}

That constructor is what is being called in this:

let beagle = new Dog("Snoopy");

This …

Dog.prototype.numLegs = 4;

… is changing the prototype but has not changed the constructor. If you check:

console.log(Dog.prototype);
// {numLegs: 4, constructor: ƒ}

Notice that it is a sibling of the constructor, it didn’t change the constructor. If you want it to affect the instances, you’d have to change the constructor.

The hasOwnProperty() method returns a boolean indicating whether the object has the specified property as its own property (as opposed to inheriting it or having it delegated from prototype).

1 Like

so. it isnt’ added to function.
maybe other function check all(function and prototyp) and will return true

Thank You for answer.

Thank you for answer.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.