CB-10522: Event binding in Hello World is misleading 15/head
authorSarangan Rajamanickam <sarajama@microsoft.com>
Fri, 5 Feb 2016 19:25:34 +0000 (11:25 -0800)
committerSarangan Rajamanickam <sarajama@microsoft.com>
Tue, 16 Feb 2016 21:32:40 +0000 (13:32 -0800)
Fixing the Hello World example

package.json
www/js/index.js

index 0f9532d..618aeb9 100644 (file)
@@ -8,7 +8,8 @@
   },
   "main": "index.js",
   "keywords": [
-    "ecosystem:cordova"
+    "ecosystem:cordova",
+    "cordova:template"
   ],
   "author": "Apache Software Foundation",
   "license": "Apache version 2.0"
index c31cd83..6963dc9 100644 (file)
 var app = {
     // Application Constructor
     initialize: function() {
-        this.bindEvents();
-    },
-    // Bind Event Listeners
-    //
-    // Bind any events that are required on startup. Common events are:
-    // 'load', 'deviceready', 'offline', and 'online'.
-    bindEvents: function() {
-        document.addEventListener('deviceready', this.onDeviceReady, false);
+        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
     },
+
     // deviceready Event Handler
     //
-    // The scope of 'this' is the event. In order to call the 'receivedEvent'
-    // function, we must explicitly call 'app.receivedEvent(...);'
+    // Bind any cordova events here. Common events are:
+    // 'pause', 'resume', etc.
     onDeviceReady: function() {
-        app.receivedEvent('deviceready');
+        this.receivedEvent('deviceready');
     },
+
     // Update DOM on a Received Event
     receivedEvent: function(id) {
         var parentElement = document.getElementById(id);