0
var bound = async.bind({},'hello','world');
bound.call({},resolve,reject);

function async(){
  console.log(arguments) //0:'hello', 1:'world', 2:resolve, 3:reject
  //what I expect: 0:resolve, 1:reject, 2:'hello', 3:'world'
}
function resolve(){}
function reject(){}

When I have a function that is already bound with some arguments, and then I use .call with extra arguments, these extra arguments are pushed (added to the end) into the arguments object of this function.

Is it any possibility, to unshift (add to the beginning) these extra arguments to the arguments object in this case when the function is already bound with some arguments?

Paweł
  • 4,238
  • 4
  • 21
  • 40
  • @NinaScholz no it's not, `log: ["hello", "world", ƒ, ƒ]` I know that it is the default behaviour of `.call`, but I'm looking for some solution to change the order of arguments. – Paweł Jul 06 '18 at 12:43
  • 1
    you may have a look here: https://stackoverflow.com/questions/45485140/bind-only-second-argument-to-javascript-function – Nina Scholz Jul 06 '18 at 12:48
  • Btw, you should never need to pass promise `resolve` and `reject` functions around. Have `async` return a self-created promise instead of taking callbacks. You might want to ask a new question about your actual problem. – Bergi Jul 06 '18 at 13:59

1 Answers1

0

You could take a different approach for binding with a function for swapping the arguments.

function resolve() {}
function reject() {}

function async() {
    console.log(arguments);
}

function swap(a, b, c, d) {
    return this(c, d, a, b);
}

var bound = swap.bind(async, 'hello', 'world');

bound.call({}, resolve, reject);
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392
  • the problem is that I haven't got the access to the arguments of bound function, except Chrome's `[[BoundArgs]]` function's property what is not a good solution. I've got only the access to **already bound** function, then I want to `.call` it with extra arguments, so these extra arguments were placed at the beginning of `arguments` object. – Paweł Jul 06 '18 at 13:10