2 ms·
I don't think you're missing anything. This is a one liner without any weird stuff. I've never heard of the author FWIW. let lea = { name: "Lea V
by recursive 6y ago
I don't think you're missing anything. This is a one liner without any weird stuff. I've never heard of the author FWIW.
let lea = {
name: "Lea Verou",
get id() {
return this.explicitId ?? this.name.toLowerCase().replace(/\W+/g, "-");
},
set id(val) {
this.explicitId = val;
}
};
console.log(lea.id);
lea.id = 'lv';
console.log(lea.id);
- ivan_ah 6y agoExactly what I was thinking! I've used this computable-valye-but-overridable-with-explicit-value pattern a couple of times, and so long as you stick to a good naming convention it works great.