I'm trying to separate the concerns in my code. I want to build a config file where i use the same method to set something. Please note that this is just for demo purpose. Is there a way that I could call the function based on either car
or bike
of the config
object selected. If so, could you please guide me?
I was getting setYear
is undefined error. I want to set the year of car object from the config object. I want to access the setYear
function using the config object.
const buildConfig = () => {
const car = {}
car.label = config['car'].label;
car.year = config['car'].setYear('2020')
console.log('car details', car);
}
const config = {
'car': {
label: 'Sedan',
setYear: setYear
},
'bike': {
label: 'Sedan',
setYear: setYear
}
}
const setYear = (year) => {
car.year = year;
}
buildConfig();