You are reading a single comment by @tve and its replies. Click here to read the full conversation.
  • Mhh, I'm also noticing that anonymous functions are evil from a space perspective. In my little test code I have:

    function sendTemp(temp, next) {
      var q = url.parse(postUrl + "?temp=" + temp);
      q.method = "POST";
      q.headers = {'Content-Length': 0};
      //console.log("REQ:", q);
      var req = http.request(q, function(resp) {
        resp.on('data', function(d) { if (d !== 'OK') console.log("Got unexpected response:", d); });
        resp.on('close', function(gotErr) {
          if (!gotErr && resp.statusCode !== "200") console.log("Got HTTP code", resp.statusCode);
          if (gotErr || resp.statusCode !== "200") errCnt++; else okCnt++;
          if (next !== undefined) next();
        });
        resp.on('error', function(err) { console.log("HTTP response error: ", err.message); });
      });
      ...
    

    Well, so the history has the whole program text as a string. The entire function sendTemp can be found in another string. Then the callback of http.request (the string starting with resp.on('data', ...) can be found as a string in the #onconnect of the http connection array. Within that, the data and the close callbacks can be found yet again in the resp object. So if I look at the if statement f (!gotErr && resp.statusCode !== "200") console.log("Got HTTP code", resp.statusCode); that's present 4 times in memory! Yikes!

About

Avatar for tve @tve started