locked
WinJS.Namespace defined methods not accessible

    Question

  • Hi,

    I have a navigation app. In the page Control corresponding js files are present. I want to access an external js file which is in the project js folder. I have specified in

    commonFunctions.js

    WinJS.Namespace.define(

    'commonFunctions', {

            authenticate: authenticate

        });

    Now when accessing the method in the PageControl's js (page2.js) file

    commonFunctions.authenticate();

    it gives an error:

    0x800a1391 - JavaScript runtime error: 'commonFunctions' is undefined

    If there is a handler for this exception, the program may be safely continued.

    Is this the right way to do this? Or am I missing something?

    Thanks,

    Neena

    • Edited by Neena IS Wednesday, October 10, 2012 3:14 AM
    Wednesday, October 10, 2012 3:12 AM

Answers

  • Yes I did. Well I have found out the answer, There was a mistake in my code.

    (function () {    WinJS.Namespace.define("commonFunctions", {       

    authenticate: function () {           

    return true;        }   

    });

    }());

    The Code was not enclosed in the function (anonymus block ();) Hence I was not able to access the method.

    • Marked as answer by Neena IS Thursday, October 11, 2012 3:55 AM
    Thursday, October 11, 2012 3:55 AM

All replies

  • This might be a dumb question, but did you reference it in the main page of the Navigation template (default.html if you haven't changed it).
    Wednesday, October 10, 2012 5:40 PM
  • Yes I did. Well I have found out the answer, There was a mistake in my code.

    (function () {    WinJS.Namespace.define("commonFunctions", {       

    authenticate: function () {           

    return true;        }   

    });

    }());

    The Code was not enclosed in the function (anonymus block ();) Hence I was not able to access the method.

    • Marked as answer by Neena IS Thursday, October 11, 2012 3:55 AM
    Thursday, October 11, 2012 3:55 AM