32 questions
1
vote
2
answers
101
views
Common check for two functions which prevents calling functions from executing further
Let's say we have two functions which first do some parameter checking. They return early if the checks are not met. Then they do stuff. Quite simple:
function funcA (inputParam) {
if(!inputParam....
2
votes
2
answers
356
views
How to wrap a function (method) with try-catch in modern javascript using decorators (native)?
without Typescript experimentalDecorators: "true"
using proposal-decorators by TC39
how can I do something like:
class LambdaFunctionExample {
lambdaResponse = [1, 2 , 3]
@...
-1
votes
2
answers
118
views
How can one access an unknown executer function from a Promise instance's construction time?
Is it possible to retrieve the implementation details of a Promise instance? Let's assume the following created promise ...
let myPromise = new Promise(function (success, error) {
/* implementation *...
-2
votes
1
answer
96
views
How does one override a method in order to intercept any call to this method?
In this widget there is a function isPermitted(). How would I intercept it and overwrite it.
I use the following to intercept other functions isPermittedDomain etc, but unable to overwrite the ...
0
votes
1
answer
263
views
How to extend/wrap/intercept/decorate a class (with custom functionality like tracing)
Question
What is the current (~2024) solution to extend/wrap/intercept/decorate a typescript class with additional behaviour to separate concerns?
There are various questions regarding wrapper classes,...
2
votes
5
answers
292
views
How to wrap / decorate / modify a function in a way that allows for additional logging before invoking and after the returning of this function?
Given the following code...
function logger = ??
function doSomething() {
logger("doSomething")
console.log("Middle of doing something")
}
Is it possible to define logger ...
0
votes
0
answers
30
views
Proxying an object in Javascript: The results from the proxied function are not being applied
What I am trying to do is intercept a function call, and prepend a header. The header is getting applied, the function itself is getting called, but the results don't have actually body.
code:
'use ...
0
votes
2
answers
1k
views
How to wrap Javascript function within function expression?
I would like to add a wrapper function to one of my functions to show extra information.
Below is my wrapper function:
var wrap = function(functionToWarp, before) {
var wrappedFunction = function() {...
0
votes
1
answer
435
views
Capturing async call response in dojo/aspect before
Trying to capture response of a async request in dojo/aspect before() event before handing it off to the original method as below:
aspect.before(ecm.model.SearchTemplate.prototype, "...
0
votes
1
answer
331
views
Dojo aspect cancel original method
I am using dojo aspect.before to perform some actions prior to calling my original method. However, I am trying to cancel the original method if some criteria is not met within the aspect.before ...
0
votes
0
answers
58
views
Any way to inject at beginning of each function in a nested object?
I have a shared object named myModule contains many common-used functions:
myModule
alert: {showAlert: ƒ}
upload: ƒ (e)
uuid: {createUuid: ƒ}
__proto__: Object
Function maybe child or great-...
0
votes
0
answers
158
views
How to track method calls and implement another method after that? (Nodejs)
In my nodejs application, I have one particular method that I want to call after execution of every method. And I don't want any code modification in methods that is being called.
I have implemented ...
1
vote
1
answer
48
views
Can i add method after method being executed meld aop
Consider I have class
function home {}{
this.door=function(){},
this.tiles=function(){}
}
I have to add some message after it's methods are called using this library called meld js (https://...
2
votes
4
answers
573
views
Java 9 Interface : Why default Modifier Converted into public Modifier
My Question is about interface. I create an interface and define four methods: first method is a private method; second is a default method; third is a static method; and fourth is an abstract method.
...
1
vote
2
answers
311
views
Reasoning behind open modifier for overriden methods
When overriding a method in Kotlin, the base class defining the method and the method itself must be declared open.
After overriding the method the derived class is final by default, while the ...
-1
votes
1
answer
244
views
How to use aspect.js in browser?
I need to use an AOP library, I found aspect.js from https://github.com/mgechev/aspect.js but I require to use it in the browser while an application is running. Does someone have any idea of how this ...
1
vote
1
answer
2k
views
What's the purpose for the variable `tmp` in this snippet?
I'm having troubling understanding the point of the variable tmp in the following code:
$.extend($.Widget.prototype, {
yield: null,
returnValues: { },
before: function(method, f) {
...
2
votes
2
answers
2k
views
fail to override setter & getter of window.location
I want to change all links assigned to window.location. So I assume location has getter & setter . That's why i cloned it & then i override the real window.location :
var clonedLocation=...
1
vote
11
answers
3k
views
Add function into the scope of another function JavaScript
I'm trying to get the example code below to work.
Edit (Trying to be more clear what the aim is):
I wan't to make all the functions and variables of the obj available in the functions setup and draw ...
0
votes
1
answer
44
views
javascript: why the return value is possible to be false
function test() {
alert(1);
return "hello";
}
Function.prototype.before = function (func) {
var __bself = this;
return function () {
if (func.apply(this, arguments) == false)
...
4
votes
3
answers
153
views
How can I apply a method modifier to a method generated by AUTOLOAD?
I have a very interesting predicament. I am working on a Perl script interface to the CVS repository and have created Perl Objects to represent Modules,Paths, and Files. Since Modules, Paths, and ...
3
votes
2
answers
635
views
Javascript console output before and after method call with AOP
I would like to measure the computing time of methods.
A nice way is (How do you performance test JavaScript code?) with console.time('Function #1'); and console.timeEnd('Function #1');
My idea ...
1
vote
4
answers
902
views
Is there a way to inject a try catch inside a function?
Maybe some of you know about AOP, in some languages using AOP can lead you to be able to inject code after, before, or while a method is executing,etc.
What I want is to apply the same in Javascript, ...
0
votes
1
answer
182
views
Moose and Roles method modifers
It is possible to use an after modifier in a Role for a required attribute that is populated in the consuming class via a builder method?
package A::Role;
use Moose::Role;
use IO::File;
use Carp;
...
2
votes
1
answer
1k
views
Enhance function prototype to call a given function before execution itself
I want to do an AOP-like 'before' functionality for JavaScript functions.
So I looked for existing solution and found the aop-plugin for jQuery. Unfortunately the plugin simply wraps the given ...
3
votes
2
answers
310
views
Moose method modifiers in base class don't get called
It's cool that it's possible to add them in sub classes or mix them in in roles. My problem is that it seems method modifiers from the base class get deactivated when subclasses redefine the method ...
2
votes
2
answers
212
views
Moose Perl: "modify multiple methods in all subclasses"
I have a Moose BaseDBModel which has different subclasses mapping to my tables in the database. All the methods in the subclasses are like "get_xxx" or "update_xxx" which refers to the different DB ...
1
vote
2
answers
2k
views
Moose around method modifier, setter and constructor (new): intercept all updates to an attribute
Update
The code I posted in my original question was illustrative of the way method modifier do or don't work.
It was not necessarily illustrative of the problem description I gave.
This code should ...
12
votes
1
answer
1k
views
In Perl/Moose, how can I apply a modifier to a method in all subclasses?
I have a Moose class that is intended to be subclassed, and every subclass has to implement an "execute" method. However, I would like to put apply a method modifier to the execute method in my class, ...
2
votes
3
answers
160
views
Can I order order method modifiers loaded as part of traits?
This is a follow up to a previous question. if I have multiple plugins/traits with around modifiers, is it possible to ensure a certain execution order (seeing as how I can't be sure which will ...
1
vote
2
answers
229
views
Pass variables around the around method modifier
Is it possible to pass variables between multiple calls to the around MethodModier? example (that doesn't work but hopefully conveys what I want to do)
sub mysub { ... };
around 'mysub' => sub {
...
3
votes
2
answers
855
views
Why doesn't Moose role application with method modifiers work in my code?
I have a Role and several classes that mix-in the role. The Role class loads all of the implementing classes so that anything that imports Blah can use them without typing a lot of 'use' lines.
...