La fonction getRegistry()
crée un objet de registre avec plusieurs propriétés, qui partagent la même structure en JavaScript:Comment obtenir DRY sur les lignes `value: _value (this.from, this.to, line)` ci-dessous?
'use strict'
function getRegistry(line) {
return {
systemId: {
from: 1, to: 3,
name: 'system_id',
value: _value(this.from, this.to, line)
},
originUnity: {
from: 4, to: 7,
name: 'origin_unity',
value: _value(this.from, this.to, line)
},
// ... similar property definition as above
}
}
function _value (from, to, line) {
return line.substring(from - 1, to)
}
module.exports = getRegistry
Comment changer la définition de la propriété dans la ligne value: _value(this.from, this.to, line)
afin d'éliminer les duplications de code?
de Nice! Ce travail pour l'instant, puisqu'il s'agit du premier objet brouillon. – ranieribt