Search code examples
javascriptfunctionmethodsextend

Javascript insert a method call inside another external function


Consider this

var obj = {
    process: function run(param) {

        return;
    }
}

and

runSomething(param);

The situation is that the run function is built elsewhere in the application and contains some additional processing that need to be done to the runSomething response.

is it possible to somehow run obj.run and insert the runSomething into it, so that runSomething can use the param that was passed in as obj.run("something")

Producing the same result as

var obj = {
    process: function run(param) {

                return runSomething(param);
             }
}

Solution

  • you can do this

        var obj = {
                process: function run(funct, param) {
    
    
                    return funct(param);
                }
            }
    
       obj.process(runSomething, param);