refactor(eslint): use cordova-eslint w/ fix (#61)

diff --git a/.eslintrc.yml b/.eslintrc.yml
new file mode 100644
index 0000000..17277f7
--- /dev/null
+++ b/.eslintrc.yml
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+root: true
+extends: '@cordova/eslint-config/browser'
+
+overrides:
+    - files: [tests/**/*.js]
+      extends: '@cordova/eslint-config/node-tests'
diff --git a/.jshintrc b/.jshintrc
deleted file mode 100644
index 27669d4..0000000
--- a/.jshintrc
+++ /dev/null
@@ -1,19 +0,0 @@
-{
-    "browser": true
-  , "devel": true
-  , "bitwise": true
-  , "undef": true
-  , "trailing": true
-  , "quotmark": false
-  , "indent": 4
-  , "unused": "vars"
-  , "latedef": "nofunc"
-  , "globals": {
-        "module": false,
-        "exports": false,
-        "require": false,
-        "cordova": true,
-        "CompassError": true,
-        "CompassHeading": true
-    }
-}
diff --git a/package.json b/package.json
index a84a1dc..ff9f103 100644
--- a/package.json
+++ b/package.json
@@ -25,8 +25,8 @@
     "cordova-browser"
   ],
   "scripts": {
-    "test": "npm run jshint",
-    "jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src && node node_modules/jshint/bin/jshint tests"
+    "test": "npm run lint",
+    "lint": "eslint ."
   },
   "author": "Apache Software Foundation",
   "license": "Apache-2.0",
@@ -38,6 +38,6 @@
     }
   },
   "devDependencies": {
-    "jshint": "^2.6.0"
+    "@cordova/eslint-config": "^3.0.0"
   }
 }
diff --git a/src/browser/CompassProxy.js b/src/browser/CompassProxy.js
index 860c258..55f160c 100644
--- a/src/browser/CompassProxy.js
+++ b/src/browser/CompassProxy.js
@@ -17,12 +17,12 @@
  * specific language governing permissions and limitations
  * under the License.
  *
-*/
+ */
 
 var Compass = {
-    getHeading: function(success, error) {
+    getHeading: function (success, error) {
         var orient = {};
-        var heading = (Math.round((Math.random() * 360) * 100) / 100);
+        var heading = Math.round(Math.random() * 360 * 100) / 100;
 
         orient.trueHeading = heading;
         orient.magneticHeading = heading;
diff --git a/src/windows/CompassProxy.js b/src/windows/CompassProxy.js
index 4302636..f587f7e 100644
--- a/src/windows/CompassProxy.js
+++ b/src/windows/CompassProxy.js
@@ -1,4 +1,4 @@
-/*
+/*
  *
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -17,17 +17,14 @@
  * specific language governing permissions and limitations
  * under the License.
  *
-*/
+ */
 
-/*jslint sloppy:true */
-/*global Windows:true, require, module, setTimeout */
+/* global Windows */
 
-var CompassHeading = require('cordova-plugin-device-orientation.CompassHeading'),
-    CompassError = require('cordova-plugin-device-orientation.CompassError');
-
+var CompassHeading = require('cordova-plugin-device-orientation.CompassHeading');
+var CompassError = require('cordova-plugin-device-orientation.CompassError');
 
 module.exports = {
-
     onReadingChanged: null,
     getHeading: function (win, lose) {
         var deviceCompass = Windows.Devices.Sensors.Compass.getDefault();
@@ -36,8 +33,8 @@
                 lose(CompassError.COMPASS_NOT_SUPPORTED);
             }, 0);
         } else {
-            var reading = deviceCompass.getCurrentReading(),
-                heading = new CompassHeading(reading.headingMagneticNorth, reading.headingTrueNorth, null, reading.timestamp.getTime());
+            var reading = deviceCompass.getCurrentReading();
+            var heading = new CompassHeading(reading.headingMagneticNorth, reading.headingTrueNorth, null, reading.timestamp.getTime());
             setTimeout(function () {
                 win(heading);
             }, 0);
@@ -50,4 +47,4 @@
     }
 };
 
-require("cordova/exec/proxy").add("Compass", module.exports);
+require('cordova/exec/proxy').add('Compass', module.exports);
diff --git a/tests/tests.js b/tests/tests.js
index 387aa58..2924d3d 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -1,33 +1,33 @@
 /*
-*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements.  See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership.  The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License.  You may obtain a copy of the License at
-*
-*   http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied.  See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*
-*/
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
 
-/* jshint jasmine: true */
+/* global CompassError, CompassHeading */
 
 exports.defineAutoTests = function () {
     var fail = function (done, message) {
-        message = (typeof message !== 'string') ? "Forced failure: wrong callback called" : message;
+        message = typeof message !== 'string' ? 'Forced failure: wrong callback called' : message;
         expect(true).toFailWithMessage(message);
         done();
-    },
-        unexpectedFailure = "Forced failure: error callback should not have been called";
+    };
+    var unexpectedFailure = 'Forced failure: error callback should not have been called';
 
     describe('Compass (navigator.compass)', function () {
         beforeEach(function () {
@@ -37,7 +37,7 @@
                         compare: function (actual, customMessage) {
                             var pass = false;
                             if (customMessage === undefined) {
-                                customMessage = "Forced failure: wrong callback called";
+                                customMessage = 'Forced failure: wrong callback called';
                             }
                             return {
                                 pass: pass,
@@ -55,19 +55,21 @@
             if (isCompassAvailable === false) {
                 // if we're already ensured that compass is not available, no need to check it again
                 done();
-                return;
             } else if (isCompassAvailable === null) {
                 // Try to access compass device, and if it is not available
                 // set hardwarefailure flag to mark some tests pending
-                navigator.compass.getCurrentHeading(function () {
-                    isCompassAvailable = true;
-                    done();
-                }, function (error) {
-                    if (error.code == CompassError.COMPASS_NOT_SUPPORTED) {
-                        isCompassAvailable = false;
+                navigator.compass.getCurrentHeading(
+                    function () {
+                        isCompassAvailable = true;
+                        done();
+                    },
+                    function (error) {
+                        if (error.code === CompassError.COMPASS_NOT_SUPPORTED) {
+                            isCompassAvailable = false;
+                        }
+                        done();
                     }
-                    done();
-                });
+                );
             } else {
                 // wait a little
                 setTimeout(function () {
@@ -76,44 +78,44 @@
             }
         });
 
-        it("compass.spec.1 should exist", function () {
+        it('compass.spec.1 should exist', function () {
             expect(navigator.compass).toBeDefined();
         });
 
-        it("compass.spec.2 should contain a getCurrentHeading function", function () {
+        it('compass.spec.2 should contain a getCurrentHeading function', function () {
             expect(navigator.compass.getCurrentHeading).toBeDefined();
-            expect(typeof navigator.compass.getCurrentHeading == 'function').toBe(true);
+            expect(typeof navigator.compass.getCurrentHeading === 'function').toBe(true);
         });
 
-        it("compass.spec.3 getCurrentHeading success callback should be called with a Heading object", function (done) {
+        it('compass.spec.3 getCurrentHeading success callback should be called with a Heading object', function (done) {
             if (!isCompassAvailable) {
                 pending();
             }
             navigator.compass.getCurrentHeading(function (a) {
                 expect(a instanceof CompassHeading).toBe(true);
                 expect(a.magneticHeading).toBeDefined();
-                expect(typeof a.magneticHeading == 'number').toBe(true);
+                expect(typeof a.magneticHeading === 'number').toBe(true);
                 expect(a.trueHeading).not.toBe(undefined);
-                expect(typeof a.trueHeading == 'number' || a.trueHeading === null).toBe(true);
+                expect(typeof a.trueHeading === 'number' || a.trueHeading === null).toBe(true);
                 expect(a.headingAccuracy).not.toBe(undefined);
-                expect(typeof a.headingAccuracy == 'number' || a.headingAccuracy === null).toBe(true);
-                expect(typeof a.timestamp == 'number').toBe(true);
+                expect(typeof a.headingAccuracy === 'number' || a.headingAccuracy === null).toBe(true);
+                expect(typeof a.timestamp === 'number').toBe(true);
                 done();
             }, fail.bind(null, done, unexpectedFailure));
         });
 
-        it("compass.spec.4 should contain a watchHeading function", function () {
+        it('compass.spec.4 should contain a watchHeading function', function () {
             expect(navigator.compass.watchHeading).toBeDefined();
-            expect(typeof navigator.compass.watchHeading == 'function').toBe(true);
+            expect(typeof navigator.compass.watchHeading === 'function').toBe(true);
         });
 
-        it("compass.spec.5 should contain a clearWatch function", function () {
+        it('compass.spec.5 should contain a clearWatch function', function () {
             expect(navigator.compass.clearWatch).toBeDefined();
-            expect(typeof navigator.compass.clearWatch == 'function').toBe(true);
+            expect(typeof navigator.compass.clearWatch === 'function').toBe(true);
         });
 
         describe('Compass Constants (window.CompassError)', function () {
-            it("compass.spec.1 should exist", function () {
+            it('compass.spec.1 should exist', function () {
                 expect(window.CompassError).toBeDefined();
                 expect(window.CompassError.COMPASS_INTERNAL_ERR).toBe(0);
                 expect(window.CompassError.COMPASS_NOT_SUPPORTED).toBe(20);
@@ -121,31 +123,31 @@
         });
 
         describe('Compass Heading model (CompassHeading)', function () {
-            it("compass.spec.1 should exist", function () {
+            it('compass.spec.1 should exist', function () {
                 expect(CompassHeading).toBeDefined();
             });
 
-            it("compass.spec.8 should be able to create a new CompassHeading instance with no parameters", function () {
+            it('compass.spec.8 should be able to create a new CompassHeading instance with no parameters', function () {
                 var h = new CompassHeading();
                 expect(h).toBeDefined();
                 expect(h.magneticHeading).toBeUndefined();
                 expect(h.trueHeading).toBeUndefined();
                 expect(h.headingAccuracy).toBeUndefined();
-                expect(typeof h.timestamp == 'number').toBe(true);
+                expect(typeof h.timestamp === 'number').toBe(true);
             });
 
-            it("compass.spec.9 should be able to create a new CompassHeading instance with parameters", function () {
+            it('compass.spec.9 should be able to create a new CompassHeading instance with parameters', function () {
                 var h = new CompassHeading(1, 2, 3, 4);
                 expect(h.magneticHeading).toBe(1);
                 expect(h.trueHeading).toBe(2);
                 expect(h.headingAccuracy).toBe(3);
                 expect(h.timestamp.valueOf()).toBe(4);
-                expect(typeof h.timestamp == 'number').toBe(true);
+                expect(typeof h.timestamp === 'number').toBe(true);
             });
         });
 
-        describe("Compass watch heading", function() {
-            it("compass.spec.10 watchCurrentHeading called with a Heading object", function (done) {
+        describe('Compass watch heading', function () {
+            it('compass.spec.10 watchCurrentHeading called with a Heading object', function (done) {
                 if (!isCompassAvailable) {
                     pending();
                 }
@@ -153,15 +155,15 @@
                 var calledOnce = false;
 
                 var watchId = navigator.compass.watchHeading(
-                    function (a){
+                    function (a) {
                         expect(a instanceof CompassHeading).toBe(true);
                         expect(a.magneticHeading).toBeDefined();
-                        expect(typeof a.magneticHeading == 'number').toBe(true);
+                        expect(typeof a.magneticHeading === 'number').toBe(true);
                         expect(a.trueHeading).not.toBe(undefined);
-                        expect(typeof a.trueHeading == 'number' || a.trueHeading === null).toBe(true);
+                        expect(typeof a.trueHeading === 'number' || a.trueHeading === null).toBe(true);
                         expect(a.headingAccuracy).not.toBe(undefined);
-                        expect(typeof a.headingAccuracy == 'number' || a.headingAccuracy === null).toBe(true);
-                        expect(typeof a.timestamp == 'number').toBe(true);
+                        expect(typeof a.headingAccuracy === 'number' || a.headingAccuracy === null).toBe(true);
+                        expect(typeof a.timestamp === 'number').toBe(true);
 
                         if (calledOnce) {
                             navigator.compass.clearWatch(watchId);
@@ -170,12 +172,12 @@
 
                         calledOnce = true;
                     },
-                    function (compassError){},
+                    function (compassError) {},
                     { frequency: 50 }
                 );
             });
 
-            it("compass.spec.11 the watch success callback should not be called once the watch is cleared", function (done) {
+            it('compass.spec.11 the watch success callback should not be called once the watch is cleared', function (done) {
                 if (!isCompassAvailable) {
                     pending();
                 }
@@ -191,14 +193,14 @@
                         if (calledOnce && !watchCleared) {
                             navigator.compass.clearWatch(watchId);
                             watchCleared = true;
-                            setTimeout(function(){
+                            setTimeout(function () {
                                 done();
                             }, 1000);
                         }
 
                         calledOnce = true;
                     },
-                    function (compassError){},
+                    function (compassError) {},
                     { frequency: 50 }
                 );
             });
@@ -211,7 +213,7 @@
 /******************************************************************************/
 
 exports.defineManualTests = function (contentEl, createActionButton) {
-    function roundNumber(num) {
+    function roundNumber (num) {
         var dec = 3;
         var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
         return result;
@@ -222,16 +224,16 @@
     /**
      * Set compass status
      */
-    function setCompassStatus(status) {
+    function setCompassStatus (status) {
         document.getElementById('compass_status').innerHTML = status;
     }
 
     // Success callback for both watchHeading and getCurrentHeading
-    function success(a) {
+    function success (a) {
         var magneticHeading = document.getElementById('magneticHeading');
-        var trueHeading = document.getElementById("trueHeading");
-        var headingAccuracy = document.getElementById("headingAccuracy");
-        var timestamp = document.getElementById("timestamp");
+        var trueHeading = document.getElementById('trueHeading');
+        var headingAccuracy = document.getElementById('headingAccuracy');
+        var timestamp = document.getElementById('timestamp');
 
         magneticHeading.innerHTML = roundNumber(a.magneticHeading);
         trueHeading.innerHTML = roundNumber(a.trueHeading);
@@ -242,8 +244,8 @@
     /**
      * Stop watching the acceleration
      */
-    function stopCompass() {
-        setCompassStatus("Stopped");
+    function stopCompass () {
+        setCompassStatus('Stopped');
         if (watchCompassId) {
             navigator.compass.clearWatch(watchCompassId);
             watchCompassId = null;
@@ -254,11 +256,11 @@
      * Start watching compass
      */
     var watchCompass = function () {
-        console.log("watchCompass()");
+        console.log('watchCompass()');
 
         // Fail callback
         var fail = function (e) {
-            console.log("watchCompass fail callback with error: " + JSON.stringify(e));
+            console.log('watchCompass fail callback with error: ' + JSON.stringify(e));
             stopCompass();
             setCompassStatus(e);
         };
@@ -271,21 +273,21 @@
         opt.frequency = 1000;
         watchCompassId = navigator.compass.watchHeading(success, fail, opt);
 
-        setCompassStatus("Running");
+        setCompassStatus('Running');
     };
 
     /**
      * Get current compass
      */
     var getCompass = function () {
-        console.log("getCompass()");
+        console.log('getCompass()');
 
         // Stop compass if running
         stopCompass();
 
         // Fail callback
         var fail = function (e) {
-            console.log("getCompass fail callback with error: " + JSON.stringify(e));
+            console.log('getCompass fail callback with error: ' + JSON.stringify(e));
             setCompassStatus(e);
         };
 
@@ -296,7 +298,8 @@
 
     /******************************************************************************/
 
-    var orientation_tests = '<h3>iOS devices may bring up a calibration screen when initiating these tests</h3>' +
+    var orientation_tests =
+        '<h3>iOS devices may bring up a calibration screen when initiating these tests</h3>' +
         '<div id="getCompass"></div>' +
         'Expected result: Will update the status box with current heading. Status will read "Stopped"' +
         '<p/> <div id="watchCompass"></div>' +
@@ -304,7 +307,8 @@
         '<p/> <div id="stopCompass"></div>' +
         'Expected result: Will clear the compass watch, so heading value will no longer be updated. Status will read "Stopped"';
 
-    contentEl.innerHTML = '<div id="info"><b>Status: </b>' +
+    contentEl.innerHTML =
+        '<div id="info"><b>Status: </b>' +
         '<span id="compass_status">Stopped</span>' +
         '<table width="100%">' +
         '<tr><td width="33%">Magnetic heading: <span id="magneticHeading"></span></td></tr>' +
@@ -314,15 +318,27 @@
         '</table></div>' +
         orientation_tests;
 
-    createActionButton('Get Compass', function () {
-        getCompass();
-    }, 'getCompass');
+    createActionButton(
+        'Get Compass',
+        function () {
+            getCompass();
+        },
+        'getCompass'
+    );
 
-    createActionButton('Start Watching Compass', function () {
-        watchCompass();
-    }, 'watchCompass');
+    createActionButton(
+        'Start Watching Compass',
+        function () {
+            watchCompass();
+        },
+        'watchCompass'
+    );
 
-    createActionButton('Stop Watching Compass', function () {
-        stopCompass();
-    }, 'stopCompass');
+    createActionButton(
+        'Stop Watching Compass',
+        function () {
+            stopCompass();
+        },
+        'stopCompass'
+    );
 };
diff --git a/www/CompassError.js b/www/CompassError.js
index 7b5b485..7861292 100644
--- a/www/CompassError.js
+++ b/www/CompassError.js
@@ -17,15 +17,15 @@
  * specific language governing permissions and limitations
  * under the License.
  *
-*/
+ */
 
 /**
  *  CompassError.
  *  An error code assigned by an implementation when an error has occurred
  * @constructor
  */
-var CompassError = function(err) {
-    this.code = (err !== undefined ? err : null);
+var CompassError = function (err) {
+    this.code = err !== undefined ? err : null;
 };
 
 CompassError.COMPASS_INTERNAL_ERR = 0;
diff --git a/www/CompassHeading.js b/www/CompassHeading.js
index 70343ee..2753f43 100644
--- a/www/CompassHeading.js
+++ b/www/CompassHeading.js
@@ -17,13 +17,13 @@
  * specific language governing permissions and limitations
  * under the License.
  *
-*/
+ */
 
-var CompassHeading = function(magneticHeading, trueHeading, headingAccuracy, timestamp) {
-  this.magneticHeading = magneticHeading;
-  this.trueHeading = trueHeading;
-  this.headingAccuracy = headingAccuracy;
-  this.timestamp = timestamp || new Date().getTime();
+var CompassHeading = function (magneticHeading, trueHeading, headingAccuracy, timestamp) {
+    this.magneticHeading = magneticHeading;
+    this.trueHeading = trueHeading;
+    this.headingAccuracy = headingAccuracy;
+    this.timestamp = timestamp || new Date().getTime();
 };
 
 module.exports = CompassHeading;
diff --git a/www/compass.js b/www/compass.js
index 603e727..ba3df60 100644
--- a/www/compass.js
+++ b/www/compass.js
@@ -17,102 +17,106 @@
  * specific language governing permissions and limitations
  * under the License.
  *
-*/
+ */
 
-var argscheck = require('cordova/argscheck'),
-    exec = require('cordova/exec'),
-    utils = require('cordova/utils'),
-    CompassHeading = require('./CompassHeading'),
-    CompassError = require('./CompassError'),
+/* global cordova */
 
-    timers = {},
-    eventTimerId = null,
-    compass = {
-        /**
-         * Asynchronously acquires the current heading.
-         * @param {Function} successCallback The function to call when the heading
-         * data is available
-         * @param {Function} errorCallback The function to call when there is an error
-         * getting the heading data.
-         * @param {CompassOptions} options The options for getting the heading data (not used).
-         */
-        getCurrentHeading:function(successCallback, errorCallback, options) {
-            argscheck.checkArgs('fFO', 'compass.getCurrentHeading', arguments);
+var argscheck = require('cordova/argscheck');
+var exec = require('cordova/exec');
+var utils = require('cordova/utils');
+var CompassHeading = require('./CompassHeading');
+var CompassError = require('./CompassError');
 
-            var win = function(result) {
-                var ch = new CompassHeading(result.magneticHeading, result.trueHeading, result.headingAccuracy, result.timestamp);
-                successCallback(ch);
-            };
-            var fail = errorCallback && function(code) {
+var timers = {};
+var eventTimerId = null;
+var compass = {
+    /**
+     * Asynchronously acquires the current heading.
+     * @param {Function} successCallback The function to call when the heading
+     * data is available
+     * @param {Function} errorCallback The function to call when there is an error
+     * getting the heading data.
+     * @param {CompassOptions} options The options for getting the heading data (not used).
+     */
+    getCurrentHeading: function (successCallback, errorCallback, options) {
+        argscheck.checkArgs('fFO', 'compass.getCurrentHeading', arguments);
+
+        var win = function (result) {
+            var ch = new CompassHeading(result.magneticHeading, result.trueHeading, result.headingAccuracy, result.timestamp);
+            successCallback(ch);
+        };
+        var fail =
+            errorCallback &&
+            function (code) {
                 var ce = new CompassError(code);
                 errorCallback(ce);
             };
 
-            // Get heading
-            exec(win, fail, "Compass", "getHeading", [options]);
-        },
+        // Get heading
+        exec(win, fail, 'Compass', 'getHeading', [options]);
+    },
 
-        /**
-         * Asynchronously acquires the heading repeatedly at a given interval.
-         * @param {Function} successCallback The function to call each time the heading
-         * data is available
-         * @param {Function} errorCallback The function to call when there is an error
-         * getting the heading data.
-         * @param {HeadingOptions} options The options for getting the heading data
-         * such as timeout and the frequency of the watch. For iOS, filter parameter
-         * specifies to watch via a distance filter rather than time.
-         */
-        watchHeading:function(successCallback, errorCallback, options) {
-            argscheck.checkArgs('fFO', 'compass.watchHeading', arguments);
-            // Default interval (100 msec)
-            var frequency = (options !== undefined && options.frequency !== undefined) ? options.frequency : 100;
-            var filter = (options !== undefined && options.filter !== undefined) ? options.filter : 0;
+    /**
+     * Asynchronously acquires the heading repeatedly at a given interval.
+     * @param {Function} successCallback The function to call each time the heading
+     * data is available
+     * @param {Function} errorCallback The function to call when there is an error
+     * getting the heading data.
+     * @param {HeadingOptions} options The options for getting the heading data
+     * such as timeout and the frequency of the watch. For iOS, filter parameter
+     * specifies to watch via a distance filter rather than time.
+     */
+    watchHeading: function (successCallback, errorCallback, options) {
+        argscheck.checkArgs('fFO', 'compass.watchHeading', arguments);
+        // Default interval (100 msec)
+        var frequency = options !== undefined && options.frequency !== undefined ? options.frequency : 100;
+        var filter = options !== undefined && options.filter !== undefined ? options.filter : 0;
 
-            var id = utils.createUUID();
-            if (filter > 0) {
-                // is an iOS request for watch by filter, no timer needed
-                timers[id] = "iOS";
-                compass.getCurrentHeading(successCallback, errorCallback, options);
+        var id = utils.createUUID();
+        if (filter > 0) {
+            // is an iOS request for watch by filter, no timer needed
+            timers[id] = 'iOS';
+            compass.getCurrentHeading(successCallback, errorCallback, options);
+        } else {
+            // Start watch timer to get headings
+            timers[id] = window.setInterval(function () {
+                compass.getCurrentHeading(successCallback, errorCallback);
+            }, frequency);
+        }
+
+        if (cordova.platformId === 'browser' && !eventTimerId) {
+            // Start firing deviceorientation events if haven't already
+            var deviceorientationEvent = new Event('deviceorientation');
+            eventTimerId = window.setInterval(function () {
+                window.dispatchEvent(deviceorientationEvent);
+            }, 200);
+        }
+
+        return id;
+    },
+
+    /**
+     * Clears the specified heading watch.
+     * @param {String} id The ID of the watch returned from #watchHeading.
+     */
+    clearWatch: function (id) {
+        // Stop javascript timer & remove from timer list
+        if (id && timers[id]) {
+            if (timers[id] !== 'iOS') {
+                clearInterval(timers[id]);
             } else {
-                // Start watch timer to get headings
-                timers[id] = window.setInterval(function() {
-                    compass.getCurrentHeading(successCallback, errorCallback);
-                }, frequency);
+                // is iOS watch by filter so call into device to stop
+                exec(null, null, 'Compass', 'stopHeading', []);
             }
+            delete timers[id];
 
-            if (cordova.platformId === 'browser' && !eventTimerId) {
-                // Start firing deviceorientation events if haven't already
-                var deviceorientationEvent = new Event('deviceorientation');
-                eventTimerId = window.setInterval(function() {
-                    window.dispatchEvent(deviceorientationEvent);
-                }, 200);
-            }
-
-            return id;
-        },
-
-        /**
-         * Clears the specified heading watch.
-         * @param {String} id The ID of the watch returned from #watchHeading.
-         */
-        clearWatch:function(id) {
-            // Stop javascript timer & remove from timer list
-            if (id && timers[id]) {
-                if (timers[id] != "iOS") {
-                    clearInterval(timers[id]);
-                } else {
-                    // is iOS watch by filter so call into device to stop
-                    exec(null, null, "Compass", "stopHeading", []);
-                }
-                delete timers[id];
-
-                if (eventTimerId && Object.keys(timers).length === 0) {
-                    // No more watchers, so stop firing 'deviceorientation' events
-                    window.clearInterval(eventTimerId);
-                    eventTimerId = null;
-                }
+            if (eventTimerId && Object.keys(timers).length === 0) {
+                // No more watchers, so stop firing 'deviceorientation' events
+                window.clearInterval(eventTimerId);
+                eventTimerId = null;
             }
         }
-    };
+    }
+};
 
 module.exports = compass;