title: javascript - what is the effect of applying prototype to functions that are not constructors?
body: <p>So, I know how to apply the prototype property to modify constructors that will effectively affect instances. Theoretically, the prototype should work on a normal function as well (though not necessarily have an effect if it's not a prototype of a certain instance). So I tried the code (createNewFunction is a normal function that's not a constructor)(full code is at the end)</p>
  
  <pre><code>createNewPerson.prototype.xx = (function() { //alerts hello
              alert("hello");
          })();   
  </code></pre>
  
  <p>I'm wondering what this actually does as to how xx is appended to the function. Is it stored as variable xx that is equal to the anon function? Or is stored as this.xx = function? How will this compare to storing the following code:</p>
  
  <pre><code>createNewPerson.xx = (function() { //alerts hello
          alert("hello");
      })();
  </code></pre>
  
  <p>This also makes me wonder as to how this this line will be stored(As in if it will be stored as var mm = 3, or it won't append at all?):</p>
  
  <pre><code>createNewPerson.mm = 3;
  </code></pre>
  
  <p>Full code for reference:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function createNewPerson(name) {
    var obj = {};
    obj.name = name;
    obj.greeting = function() {
      alert('Hi! I\'m ' + this.name + '.');
    };
    return obj;
  }
  
  createNewPerson.mm = 3; //does nothing when i tested it     
  
  createNewPerson.xx = (function() { //alerts hello
    alert("hello");
  })();
  createNewPerson.prototype.xx = (function() { //alerts hello
    alert("hello");
  })();
  var salva = createNewPerson('Salva');</code></pre>
  </div>
  </div>
  </p>