someObject: = {
... // properties and stuff
performComputation: function() {
let data = this.data;
return this.x * data.amount;
}
}
someObject: = {
... // properties and stuff
performComputation: function() {
let data = applyFilters('computationData', this.data);
return applyFilters('computationResult', this.x * data.amount);
}
}
##Edit
It seems that my goal is being misunderstood, so I'll try to explain it better. The Observable pattern or Event dispatching allows me to run code within the execution of another code. However, the reason why it is not enough for me is specifically because Observers don't return values that can be manipulated.
As for AOP, as pointed out by Candied Orange's answer, the target doesn't know it's being hooked on. Which is also not my goal.
My goal is for a function to expose certain pieces of data for other functions to hook on and manipulate.
Again, with another example pseudo-code:
someObject = {
name: "Jim",
greet: function(str) {
let greeting = applyFilters('greeting', str);
return `${greeting} I am ${name}.`;
}
}
addFilter('greeting', (str) => { return str.toUppercase(); });
addFilter('greeting', (str) => { return str + "!!"; });
someObject.greet("Hello"); // => HELLO!! I am Jim.
This is the kind of functionality I need, and it can be easily implemented with iterating over callbacks as I mentioned, but I am not sure if this is in any way a good pattern or if I have alternatives to achieve this goal.