Is there a better way to write this? Ideally I want to write pre_calculated_h
inside the object literal, somehow.
const obj = {
long_calc_f(x) {return 5*x}, //Some time consuming calculation
g(x) {return x + 2},
}
obj.pre_calculated_h = function(n) {
const pre_calculated_values = []
for (var i = 0; i < n; i++) pre_calculated_values.push(this.g(this.long_calc_f(i)))
return function(x) {return pre_calculated_values[x]}
}.call(obj, 20)