News for hackers. Stuff that matters.
Re:Show HN: I built an extension of JavaScript in a day by chmod775 on Saturday August 16, 2014 @05:56PM (#8187706)
The JavaScript result of your example looks like this:

(again, beautified because DesignToJS crams everything in one line to preserve the line numbers of your actual code):

  function loadAndPrintFile(contents) {
    if (!contents) {
      fs.readFile(function(error, contents){
        if(error !== null && error !== undefined){
          return error;
        }
      });
    }
    console.log(contents);
  }
If you omit the function body, it will only expand to the end of the current logical 'context' (or whatever it's called)

I'd suggest writing it like this in DesignToJS:

  loadAndPrintFile: (contents! console.log) {
    fs.readFile() -> (error!, contents! console.log)
  }
Result looks like this:

  function loadAndPrintFile(contents) {
      if(contents !== null && contents !== undefined){
          return console.log(contents);
      }
      fs.readFile(function(error, contents){
          if(error !== null && error !== undefined){
              return error;
          }
          if(contents !== null && contents !== undefined){
              return console.log(contents);
          }
      });
  }

Edit: I just submitted a patch that avoids unnecessary binding of 'this' if 'this' is not actually used.
Re:Show HN: I built an extension of JavaScript in a day by asynchrony on Sunday August 17, 2014 @12:32PM (#8189717)
In Javascript (contents !== null && contents !== undefined) is equivalent to (contents != null).
Re:Show HN: I built an extension of JavaScript in a day by chmod775 on Sunday August 17, 2014 @03:52PM (#8190250)
Now that is good to know, thank you. I'll make that change asap.
Re:Show HN: I built an extension of JavaScript in a day by dmitrig01 on Saturday August 16, 2014 @07:01PM (#8187889)
Ah, very interesting use of the ! operator.