3 ms·
Bonus points for being meta? function createOlympian() { let props = ['name', 'sport', 'country'] let olympian = { log() { c
by insin 10y ago
Bonus points for being meta?
function createOlympian() {
let props = ['name', 'sport', 'country']
let olympian = {
log() {
console.log(props.map(prop => this[prop]).join(', '))
}
}
props.forEach(prop => {
olympian[prop] = function(value) {
this[prop] = value
return this
}
})
return olympian
}
- tkxxx7 10y agoThis is neat, but those functions can only be used once.