Obviously, this exact syntax does not exist in Javascript, but there is a method Object.definePropertythat can be used to achieve something very similar. Basically, this method allows you to create a new property for a specific object and, as part of all the features, define a getter method that is used to calculate the value.
Here is a simple example to get you started.
var example = {
'count': 10
};
Object.defineProperty(example, 'evenCountList', {
'get': function () {
var numbers = [];
for (var number = 0; number < this.count; number++) {
if(number % 2 === 0) {
numbers.push(number);
}
}
return numbers;
}
});
, @property , Object.defineProperty. , MDN.