0

In one project I found the following code :

this.moveNode(node = this.getChildOf(node));

Could anyone explain what will be passed to moveNode after node = this.getChildOf(node) is executed?

  • there is probably a field/variable declared before that called `node`, and before calling `this.moveNode` he is assigning `node` with the result of `this.getChildOfNode(node)` – vc73 Apr 19 '19 at 09:54

2 Answers2

3

Your code is equivalent to

node = this.getChildOf(node);
this.moveNode(node);

You should refactor it in two separate instructions as I did above, because it makes the code more readable and obvious. It's also easier to debug, because you can more easily choose to put the breakpoint wherever you want.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
1

This will pass as expected the return of this.getChildOf(node).

The execution will follow this order:

  1. this.getChildOf(node) is called.
  2. The assign to node is made.
  3. this.moveNode() is called.
Miguel Ruivo
  • 16,035
  • 7
  • 57
  • 87