title: Objects and functions in javascript
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/13418669/javascript-do-i-need-to-put-this-var-for-every-variable-in-an-object">Javascript: Do I need to put this.var for every variable in an object?</a>  </p>
  </blockquote>
  
  
  
  <p>I'm struggling to understand functions and objects in javascript. It is said that also functions are objects and objects are kind of "associative arrays" i.e. collections of key-value pairs. I understand that if I write</p>
  
  <pre><code>function myFunction() {
      var value = 0;
  }
  alert(myFunction.value); //then this gives me "undefined"
  </code></pre>
  
  <p>because variables have function scope. But if I write</p>
  
  <pre><code>function myFunction() {
      this.value = 0;
  }
  alert(myFunction.value); //then this gives me "undefined" too.
  </code></pre>
  
  <p>But finally, If I write</p>
  
  <pre><code>function myFunction() {
      this.value = 0;
  }
  myFunction.value = 0;
  alert(myFunction.value); //then this gives me 0
  </code></pre>
  
  <p>So I can give myFunction property "value" but from "outside". Can someone explain what is going on and why this.value = 0; doesnt create property "value".</p>