0

I found one interesting thing for me, but can't understand it.

function getPaths(dir, ext) {
  return new Promise(function(resolve, reject) {
    execFile('find', [dir], function(err, stdout, stderr) {
      if (err) reject(err);
      let fullList = stdout.split('\n');
      let filteredList = fullList.filter(function(el){
        if (path.extname(el) === ext) {
          return true;
        } else {
          return false;
        }
      }); 
      resolve(filteredList);
    });
  });
}

And I get in console next message: "SyntaxError: Unexpected identifier". But if I replace "let" by "var" it works right!

Does anybody can tell me why it is? I use node v. 6.3.1 (also tried with v. 0.12.15), ubuntu 14.04 LTS.

  • 1
    You do not need to say `if (b) return true; else return false;`. You can say `return b;`. –  Aug 13 '16 at 19:47
  • Assuming `b` is of form `x === y` like in his code, otherwise rather `return !!b;` i'd think – ASDFGerte Aug 13 '16 at 19:51
  • Add 'use_strict' at file begin. Perhaps in `if (err) reject(err);` missed `return`. – Aikon Mogwai Aug 13 '16 at 19:55
  • My guess is that you're running the code using Node 0.12 each time, because that version _will_ throw that error. Are you using something like `nvm` to install multiple version of Node? Are you using `sudo`? – robertklep Aug 13 '16 at 19:57
  • It's not important how I'm filtering this array by CB - same result. In strict mode now in console printed "SyntaxError: Use of const in strict mode." Yes, I use node versions manager. It's a lot of information about work with NVM. – Nacalyator Aug 13 '16 at 22:19
  • 1
    @robertklep Thank you for your comment! It was really as you say! Terminal with command "node --version" shows "6.3.1", but when I used command ":!node --version" in vim it shows 0.12.13. With command "nvm alias default v6.3.1" I fixed this. – Nacalyator Aug 13 '16 at 23:53

0 Answers0