Extending javascript function with parameters

0

I would like to know if it is possible to extend a javascript function without having to repeat the parameters, as if it were a constructor,

function DefaultRun(args1,args2) {
}

function Run(args1, args2){
    DefaultRun.call(this,
        args1,
        args2);
}

Run.prototype = Object.create(DefaultRun.prototype);

Would you have any way to do this?

function DefaultRun(args1, args2, args3) {
}

function Run(){
    DefaultRun.call(this);
}

Run.prototype = Object.create(DefaultRun.prototype);

That is, adding an argument in the parent always needs to add in all of your children. Is it possible?

Edit ----

I need this, because I use this function in several files that have a controller in angularjs, in this style:

function Run(){
    DefaultRun.call(this, ...arguments);
}

Run.prototype = Object.create(DefaultRun.prototype);

angular.module("APP").run(Run);

However, for example to use $scope , I need to set this in the Run function, that is, if I need to add some parameters, I will need to add in all the files that use it as Father.

    
asked by anonymous 23.10.2018 / 21:01

1 answer

1

In JavaScript, when you invoke a function, all arguments are stored in an object / array named arguments, regardless of whether you have declared the parameters or not, so I suppose using DefaultRun.call(this, ...arguments); would automatically send all arguments to the parent constructor, generating behavior similar to what you want.

    
23.10.2018 / 21:10