title: Where are the rules on JavaScript function scope in QML defined?
body: <p>I'm trying to nail down the specifics of function scope in QML. The examples in the documentation appear to often be incorrect (or incomplete). I'll take a pretty typical example right from the <a href="http://qt-project.org/doc/qt-5/qtqml-javascript-hostenvironment.html#javascript-environment-restrictions" rel="nofollow">JavaScript Host Environment doc page</a>. I'm using Qt 5.3.</p>
  
  <pre><code>Item {
     width: 200; height: 100
     function mouseAreaClicked(area) {
         console.log("Clicked in area at: " + area.x + ", " + area.y);
     }
     // This will not work because this is undefined
     MouseArea {
         height: 50; width: 200
         onClicked: mouseAreaClicked(this)
     }
     // This will pass area2 to the function
     MouseArea {
         id: area2
         y: 50; height: 50; width: 200
         onClicked: mouseAreaClicked(area2)
     }
  }
  </code></pre>
  
  <p>If I take this and paste it into a new empty project right inside the root ApplicationWindow object it doesn't work. I've seen many examples like this and they all behave the same.  The call to the function mouseAreaClicked() generates a Reference Error. I can either move the function up so that it's directly inside the root object, or I can assign an id and call the function through the id. </p>
  
  <p>Is this how this is supposed to work? Are functions only available if they are part of the root object? Is this something that changed recently? Is it releated to the ApplicationWindow object? I can't find any mention of this in the documentation. Also this example is somewhat interesting because the topic under discussion: the <strong>this</strong> pointer, doesn't behave as described. The code invoked by the first MouseArea works just as well as the code invoked by the 2nd MouseArea so I'm also not sure what to make of that. </p>
  
  <p>Any insight appreciated.</p>