Is it possible to dynamically append to the prototype of an object's instance? For example, I have two dell objects, one's a laptop and one's a desktop. I want to be able to create two instances of dell and then extend the prototype to either laptop or desktop so I can use the appropriate getters / setters.
JSFiddle link: http://jsfiddle.net/QqXgV/1/
var dell = function(){}
dell.prototype = new computer();
dell.prototype.constructor = dell;
var hp = function(){}
hp.prototype = new computer();
hp.prototype.constructor = hp;
var computer = function(){}
computer.prototype.setType = function(type){
//Here is where I would extend.
this.prototype extends window[type].prototype;
}
var laptop = function(){}
laptop.prototype.getKeyboard = function(){
return "motherboard";
}
var desktop = function(){}
desktop.prototype.getKeyboard = function(){
return "usb";
}
var dellDesktop = new dell();
dellDesktop.setType("desktop");
var dellLaptop = new dell();
dellLaptop.setType("laptop");
//This is the end goal.
dellDesktop.getKeyboard(); //Returns usb
dellLaptop.getKeyboard(); //Returns motherboard
//And then be able to do the same thing with hp.