Javascript Abstract Class with Object create

Viewed 313

This is my Abstract class:

var Animal = function(){
    this.name = ''
    this.legs = 0;
    throw new Error("cannot instantiate abstract class");
}
Animal.prototype.walk = function(){ console.log(this.name+ " walked")};

Creating a new Concrete Class:

var Dog = function(){} ;

Now I want to make a concrete class Dog to inherit from abstract class Animal. I tried both ways below. Which one is the standard?:

Dog.prototype = Object.create(Animal.prototype)

OR

Dog.prototype = Animal.prototype

I also tried var Dog = Object.create(Animal)which gave me an error.

1 Answers
Related