Assume I have:
function Pet(){}
Pet.prototype.breathe = function(){}
And
function Cat(){}
Afterwards, I execute:
Cat.prototype = Object.create(Pet.prototype)
Cat.prototype.purr = function(){}
I am aware that
var cat = new Cat()
console.log(cat instanceof Pet); //true
However, how can I verify if the function Cat
is going to be an instance of Pet
without actually initializing it?
The solution that comes to mind, albeit simple and a bit hacky, is...
Pet.prototype.$$pet = true
And then verify
console.log(Cat.prototype.$$pet) //true
But this method doesn't seem very elegant because I could just easily modify
Cat.prototype.$$pet = true