locked
Declaration of a Global Variable RRS feed

  • Question

  • HI,

    I wanted to know how to declare a variable that is accessible across all my JS files in my project. I want to access a variable in MainPage.js from Data.js. I haven't found a solution yet. Any help would be greatly appreciated. This is a bit urgent.

    Regards

    Rahul


    Rahul

    Saturday, January 12, 2013 5:00 PM

Answers

  • I finally found a solution myself. I am posting it here so that other people wont have to search around for it.

        WinJS.Namespace.define("Name", {
            Data: WinJS.Binding.as({            
             Content: ""
    })    });


    Rahul

    • Marked as answer by Rahul Dominic Sunday, January 13, 2013 10:35 AM
    Sunday, January 13, 2013 10:28 AM

All replies

  • I don't think you would be able to, that variable is either local or global but only with in it's own .js.

    If you could some how pass it to the other script then that's how you would do it, well at least that's how you would do it in Java but JavaScript was designed for a different purpose so I don't even know if it is possible.

    Sunday, January 13, 2013 12:48 AM
  • I finally found a solution myself. I am posting it here so that other people wont have to search around for it.

        WinJS.Namespace.define("Name", {
            Data: WinJS.Binding.as({            
             Content: ""
    })    });


    Rahul

    • Marked as answer by Rahul Dominic Sunday, January 13, 2013 10:35 AM
    Sunday, January 13, 2013 10:28 AM
  • Hi Rahul,

    Just for your information, if you want to use js intellisense in VS IDE when
    editing the js code for your windows store app, make sure you have added the
    <script src= .... ></script> reference for all the js files (your
    own or 3rd party library) in the same html page's <head> section.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 14, 2013 3:59 AM
    Moderator