In a case where a Dell can be either a Laptop or a Desktop one might create a DellLaptop and a DellDesktop constructor. But Laptops come in ultrabooks and netbooks so one has to create DellLaptopUltrabook and DellLaptopNetBook. So in a case where something can be either this or that and other objects can be this or that (like HP can also be either Laptop or Desktop) maybe the following pattern can help out:
var Computer = function(){};
//proxy getKeyboard based on what type it is
Computer.prototype.getKeyboard = function(){
return this.type.getKeyboard.call(this);
};
var Dell = function(args){
//do some checks on args here
//re use Computer constructor
Computer.call(this.args);
//re use laptop or Desktop constructor code
args.type.call(this,args);
//re use Laptop or Desktop protype members
this.type=args.type.prototype;
};
Dell.prototype = Object.create(Computer.prototype);
Dell.prototype.constructor = Dell;
var Laptop = function(){};
Laptop.prototype.getKeyboard = function(){
return "motherboard";
};
//ultrabook and netbook can inherit from Laptop
// so you could pass UltraBook or Netbook as type
var Desktop = function(){};
Desktop.prototype.getKeyboard = function(){
return "usb";
};
var dellDesktop = new Dell({type:Desktop});
var dellLaptop = new Dell({type:Laptop});
//This is the end goal.
console.log(dellDesktop.getKeyboard()); //Returns usb
console.log(dellLaptop.getKeyboard()); //Returns motherboard