Skip to main content
Commonmark migration
Source Link

###So, here are my questions:

So, here are my questions:

##Edit

Edit

###So, here are my questions:

##Edit

So, here are my questions:

Edit

Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
Source Link

As for AOP, as pointed out by Candied Orange's answerCandied Orange's answer, the target doesn't know it's being hooked on. Which is also not my goal.

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.

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.

Bumped by Community user
Tweeted twitter.com/StackSoftEng/status/838569193150767107
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Added more examples and clarified the question
Source Link
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.

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);
    }
}
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.

Source Link
Loading