Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9129385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:44:04+00:00 2026-06-17T07:44:04+00:00

This is my main file: $(document).ready(function () { function Page() { this.menu = new

  • 0

This is my main file:

$(document).ready(function () {
  function Page() {
    this.menu = new Menu();
    this.management = new Management();
    this.text = "text";
  }
window.Page= Page();
});

Now I want to access the Page from every other JS file:

I tried this:

console.log(Page.text);

Gives me : Uncaught ReferenceError: Page is not defined

Tried this:

console.log(window.Page.text);

Gives me : Uncaught TypeError: Cannot read property 'text' of undefined

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:44:05+00:00Added an answer on June 17, 2026 at 7:44 am

    Your issue is that within the Page function you are not creating any new object on the global context. You are creating a new Menu and new Management instance but on the current context.

    Plus by calling the Window.Page = Page(), you are assigning the result of the Page function (which is void) to the window.Page object.

    I suggest you do something like :

    //- from any js file 
        function createPage() {
                var newPage = { title : 'new page', count : '2' };
                return newPage;
              }
        window.Page = createPage();
    

    …

    //- and from other js file
        $(document).ready(function () {                
        alert(window.Page.title);
        });
    

    Note, I have replaced your menu and management properties with dummy content for this sample. Sample available @ this JSFiddle

    Update : Code has been updated to illustrate the multiple js file proper usage.

    Hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this js file serving from some domain say foobar.com at http://foobar.com/static/js/main.js: $(document).ready(function()
I have Javascript function defined in the main index.html file. One part of this
i have this files: JAVASCRIPT $(document).ready(function(){ $('a').click(function(){ $('div').load(formular.html,function(){ $('input[type=submit]').click(function(){ $('form').submit(); }); }); }); });
I have this jq function to open a link inside a div: $(document).ready(function() {
Initially cufon replaces the main page text. After loading another page file, cufon doesn't
This is my HTML page: <head> <meta http-equiv=Content-Type content=text/html; charset=UTF-8 /> <title>Untitled Document</title> <script
I have a code that looks like this: int main () { fstream file;
My included file (include.php) is this: <?php $myarray=(a,b,c); shuffle($myarray); ?> My main php file
This is my code: int main(int argc, char *argv[]){ FILE *fp; char *tmp, *tmp2,
There is this output of objdump on some object file: $ objdump -h main.o

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.