Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The comments explain why.</p> <p>You need to notify the app that the device is ready. The <code>this</code> object in the context is the event itself. </p> <p>It would be like calling <code>event.receivedEvent</code>.</p> <p>You nee to notify the application that the device is ready, hence the <code>app</code> call.</p> <p>Edit: to further clarify, <code>this</code> is the context of <code>app</code> with the app object except in the <code>onDeviceReady</code> function. The <code>bindEvents</code> function runs this code:</p> <pre><code>document.addEventListener('deviceready', this.onDeviceReady, false); </code></pre> <p>Which binds <code>onDeviceReady</code> to an event via <code>addEventListener</code> which changes the context of <code>this</code> from <code>app</code> to the <code>event</code>.</p> <p>This means, you cannot call methods from <code>app</code> via the <code>this</code> keyword with that changed context. Hope this helps clarify a bit more.</p> <p>Edit 2: see this code for some demonstration: <a href="http://jsbin.com/UGerika/1/edit?html,js,output" rel="nofollow">http://jsbin.com/UGerika/1/edit?html,js,output</a></p> <pre><code> // http://jsbin.com/UGerika/1/edit?html,js,output // Demonstrates the scope of 'this' variable once a // function is bound to event receiver. var app = { var1: function(){ return "i am this"; }, initialize: function() { this.bindEvents(); }, bindEvents: function() { alert('bindevents'); this.onWindowClick(); }, onWindowClick: function() { // in this case, this.var1 is perfection valid // 'this' is still scoped to 'app' object. alert(this.var1); } }; var app2 = { var1: function(){ return "i am this"; }, initialize: function() { this.bindEvents(); }, bindEvents: function() { alert('bindevents'); document.addEventListener('mousedown', this.onWindowClick, false); }, onWindowClick: function() { // in this case, this.var1 is invalid // 'this' is scoped to 'mousedown' event. // we would have to call app2.var1 alert(this.var1); } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload