I have a module Vehicle that contains general vehicle info. I have another module Car, which adds more functionality to Vehicle object.
// Pseudo code only. The final functions do not have to resemble this
var vehicle = require('vehicle')
vehicle.terrain = 'Land'
var car = vehicle.createCar()
// car and anotherCar will have unique Car-related values,
// but will use the same Vehicle info
var anotherCar = vehicle.createCar()
I am looking at using Object.create for the Car module, but not sure where the Object.create calls should go.
- Should I have a constructor in the Car module that takes an instance of a Vehicle object and does an Object.create with the Vehicle instance as the prototype?
- Or should the Object.create happen in a function on the Vehicle object, like createCar? My issue with this way, is Car should care that it's derived from Vehicle, Vehicle shouldn't know Car requires that.
- Or even if Object.create is the right approach.
Please, any examples and best practices would be greatly appreciated.
Update:
I changed the example to better reflect the inheritance problem I'm trying to solve.