/* Base class */var Person = {name: 'default name', getName: function () {return this. name ;}};
Common Methods
Function clone (object) {function F () {} F. prototype = object; return new F ;}
/* Subclass 1 */var reader = clone (Person); alert (reader. getName (); // This will output 'default name '. reader. name = 'John Smith '; alert (reader. getName (); // This will now output 'John Smith '. /* subclass 1 */var Author = clone (Person); Author. books = []; // Default value. author. getBooks = function () {return this. books ;}
Var author = [];/* define instance */author [0] = clone (Author); author [0]. name = 'dustin diaz'; author [0]. books = ['javascript Design pattern']; author [1] = clone (Author); author [1]. name = 'ross Harmes '; author [1]. books = ['javascript Design pattern']; author [1]. getName (); author [1]. getBooks ();