Is bad practice shadow callback variables?

Take for example the asynchronous function Node fs.stat(). If I need to use fs.stat()in the file, do it later, the result will be obscured.

fs.stat(file, function(err, stats) {
  fs.stat(file, function(err, stats) {
  });
});

The variable is changed err, as well as the variable stats- does it even matter if I do not use the first callback inside the second? Is it better to rename the second callback variable?

Does these variables overwrite one or more times any performance impact?

+5
source share
2 answers

A question of opinion, but I would say yes - bad practice. In any case, there are two problems:

  • ( ), .

  • - , (, , ?). .

.

+6

, . , . - , , ,

err stats ?

fs.stat(file, function(err, stats) {
                        \\    \\
                         \\    \\
  fs.stat(file, function(err, stats) {
  });
});

, . , .

, , . , , .


Update:

, .

:

  fs.stat(file, function(err, stats) {

  });

  //Another similar functions somewhere with same varialbes
  fs.stat(file2, function(err, stats) {
  });
0

All Articles