You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function Animal() {
if (!this.__extending) {
throw "cannot create a new instance of Animal because it is abstract.";
}
}
function Snake() {
this.__extending = true;
Animal.call(this);
}
Snake.prototype = Object.create(Animal);
var snake = new Snake(); // ok
var animal = new Animal(); // error - Animal is abstract
This, while a good solution, is adding runtime code, which is bad.
I'm beginning to think that we need a compiler flag to specify if it's a production or development build, and only put these kinds of things in production.
Also, line 3 should be throw new Error("Cannot create a new instance of Animal because it is abstract.");
The abstract modifier indicates that a function has a missing or incomplete implementation. Useful for inheritance.
The text was updated successfully, but these errors were encountered: