I am trying to find JavaScript inheritance. Vaguely, it seems that there are many different approaches - Crockford presents a lot of these, but can’t just look into his prose (or maybe just not related to my specific scenario).
Here is an example of what I still have:
var Item = function( type, name ) {
this.type = type;
this.name = name;
};
var Book = function( title, author ) {
this.name = title;
this.author = author;
};
Book.prototype = new Item('book');
var book = new Book('Hello World', 'A. Noob');
This approach leaves me with enough redundancy because I cannot delegate instance-specific attributes to the base class (the attribute value is unknown at the time the prototype is assigned). Thus, each subclass must repeat this attribute. Is there a recommended way to solve this problem?
Bonus question: is there a reasonable way to avoid the “new” operator, or will it be considered a novice working against the language?