JavaScript: inline function vs. regular statements
<p>Once again I found JavaScript code on the Internet that contains an inline function where, in my opinion, regular statements would make just as much sense. Here's the first sample:</p>

<pre><code>function outerHTML(node){
  // if IE, Chrome take the internal method otherwise build one
  return node.outerHTML || (
         function(n) {
           var div = document.createElement('div'), h;
           div.appendChild(n.cloneNode(true));
           h = div.innerHTML;
           div = null;
           return h;
         })(node);
}
</code></pre>

<p>If you'd ask me to code the same thing, it would look like this:</p>

<pre><code>function outerHTML(node){
  var div, h;

  // if IE, Chrome take the internal method otherwise build one
  if (node.outerHTML) {
    return node.outerHTML;
  }

  div = document.createElement('div')
  div.appendChild(node.cloneNode(true));
  h = div.innerHTML;
  div = null;

  return h;
}
</code></pre>

<hr>

<p><strong>EDIT</strong>: <em>As <a href="http://stackoverflow.com/questions/7510810/javascript-inline-function-vs-regular-statements/7510932#7510932">OverZealous stated</a>, there is a difference in logic on this one. I leave it here so nobody gets confused about that answer.</em></p>

<p>And maybe another original sample (<em>yes, this doesn't "compile" as it's just a code fragment</em>):</p>

<pre><code>addGetters: function (attributes) {
  var that = this;
  function addGetter(attr) {
    that.prototype["get" + attr.capitalize()] = function() { return this[attr]; };
  }

  for(var i = 0; i &lt; attributes.length; i++) {
    var attr = attributes[i];
    addGetter(attr);
  }
},
</code></pre>

<p>compared to my attempt</p>

<pre><code>addGetters: function (attributes) {
  for(var i = 0; i &lt; attributes.length; i++) {
    var attr = attributes[i];
    this.prototype["get" + attr.capitalize()] = function() { return this[attr]; };
  }
},
</code></pre>

<hr>

<p>Is there a difference? Doesn't the original version consume more space since a function needs to be created and/or isn't it slower because of this? Is there a possible memory leak?</p>

<p>The utilisation of CPU and memory is very important as I'm coding in an environment where both are limited and any "less" is good. And since there's no <code>sizeof()</code> in JavaScript and its implementation attempts aren't safe to interpret any thinking-ahead-fixes are important.</p>

<p><em>Please note that as far as the "my version" is concerned I didn't test it. I'm just trying to explain what I'm trying to ask.</em></p>

<p><strong>EDIT</strong>: Even though this question has an answer, I'm still wondering about the memory utilisation. If somebody has some insights, please don't hesitate to add it here.</p>
