title: Javascript developer from C#
body: <p>I have always been taught with object-oriented paradigms when developing and rarely made use of JavaScript until about a year ago. I have taken many of my object-oriented skills with me which, for the most part, have served me will in JavaScript.</p>
  
  <p>However, looking at some of the JavaScript libraries, some of their JavaScript is much, much more advanced. What I tend to do is, in a very C# manner, write the outline of my HTML page as follows:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
      &lt;!-- some meta tags &amp; import statements --&gt;
      &lt;script&gt;
          function x() {
              // do some stuff
          }
  
          function y() {
              // do some more stuff
          }
  
          function z() {
              // do some final stuff
          }
      &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;!-- some markup --&gt;
      &lt;a onclick="x()"&gt;Call function x&lt;/a&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>Which, as you'll see, is just some function declarations (obviously I have omitted a lot of detail to save time and unnecessary reading); but I want to take it to another level - but before I do, is there anything wrong with the above pattern?</p>
  
  <p>Would I gain any benefit if I was to use self-executing functions which I understand are the correct way of writing JavaScript, and the cleanest way? If so, then I am confused by their use? I understand that they give developers a closed environment (where developers can split code into private/public functions); and stop developers adding to the 'window' variable.</p>
  
  <p>Do I put my entire  tags into a self-executing function? I understand it won't work immediately after putting it into a self-executing function, but I would like to at least try to make my code cleaner.</p>
  
  <p>Two books I have (JavaScript: The Definitive Guide (Definitive Guides) by David Flanagan and Pro jQuery by Adam Freeman) are good at describing individual features of the language, but less so how to write entire libraries etc.</p>
  
  <p>So if anyone could give any pointers, it would be much appreciated! Thanks.</p>