0

I have just seen a function written as followed:

function(callback, traversal) {
    traversal.call(this, callback);
};

Does this code mean calling the 2nd function traversal with the 1st function callback as the parameter and pass this as this object into traversal function call? Is this the old way of writing this kind of function? What is the ES6 way of writing it?

newguy
  • 5,668
  • 12
  • 55
  • 95
  • 1
    ES6 way to write this would be `traversal.call(this, callback);`. – dfsq Mar 07 '17 at 11:06
  • 1
    Well, there's a certain amount of manipulation of `this` going on, but you'd probably want to see the wider scope of the code to tell whether you could more concisely write it with arrow functions etc. – James Thorpe Mar 07 '17 at 11:06
  • @JamesThorpe this code is extracted from a Tree implementation in javascript. I would like to see if it is possible to rewrite it using arrow function. But I guess maybe the author just want to have a more flexible implementation. – newguy Mar 07 '17 at 11:09
  • 1
    @newguy instead of talking about the code, paste it – Mulan Mar 07 '17 at 13:11
  • Potentially related: [Arrow function vs function declaration / expressions: Are they equivalent / exchangeable?](https://stackoverflow.com/questions/34361379/arrow-function-vs-function-declaration-expressions-are-they-equivalent-exch) – Felix Kling Mar 07 '17 at 16:40

0 Answers0