I'm stuck on figuring out how to do multi-level inheritance while using Object.create() as opposed to traditional constructors. I've opened a fiddle here .
We have two types of objects, programmers, and a "subclass" front-end developers. Programmers inherits from the programmer prototype object, and as you can see, all programmers can be awkward.
var programmerProto = Object.create(Object.prototype,{
beAwkward: {value: function(){
return "Yeah I uhh, AHEM, *shuffles feet*";
}
}
});
function programmerFactory (name, age, neckbeard){
return Object.create(programmerProto, {
name: {writable: true, enumerable: true, value: name},
age: {writable: false, enumerable: true, value: age},
neckbeard: {writable: true, enumerable: true, value: neckbeard}
});
}
Now for frontend developers, they have their own common traits, so we need a new prototype object as defined. But, front-end devs are also programmers, so we make the front-end prototype object as follows:
var frontEndProto = Object.create(programmerProto, {
beSmooth: {
value: function(){
return "Excuse me ma'am, could I interest you in a, fish sandwich?";
}
},
preferredLanguage: {writable: true, enumerable: true, value: 'JS'}
});
Now we hit the problem. I want to use a factory method to create instances of the frontend developers, so I can add some front-end specific property like "CSS3_skillz" or something. But if I use Object.create(frontEndProto, "..."), that ... is going to be all the code I already wrote in the programmerFactoryFunction. If I call programmerFactory from within frontEndFactory, then the prototype of the returned object is programmerProto instead of frontEndProto. What's the proper way to handle this?