bradxr
8/5/2018 - 11:00 PM

Understand the Constructor Property

There is a constructor property located on object instances, it is a reference to the constructor function that created the instance It's possible to check this property to find out what kind of object it is, however it can be overwritten so it's best to use instanceof if possible

let duck = new Bird();
let beagle = new Dog();

console.log(duck.constructor === Bird); //prints true
console.log(beagle.constructor === Dog); //prints true


function joinBirdFraternity(candidate) {
  if (candidate.constructor === Bird) {
    return true;
  } else {
    return false;
  }
}