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 630503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:51:43+00:00 2026-05-13T19:51:43+00:00

In a CMS I’m building I want to have my own javascript namespaced object

  • 0

In a CMS I’m building I want to have my own javascript namespaced object $cms. This object should have a method/function hasIdentity that returns the status of whether the user is logged in.

Is there a way that I can have this method/function return the status without having to resort to either:

  • AJAX
  • a global var
  • or rewriting the following script from within PHP

This is what I have so var:

var $cms = {
    hasIdentity: function()
    {
        return /* the status provided by PHP */;
    }
};

It’s a bit of a esthetic matter perhaps, but I don’t want to resort to this:

// write this global var;
var $isLoggedIn = false;

var $cms = {
    hasIdentity: function()
    {
        return $isLoggedIn;
    }
};

Or this:

var $cms = {
    hasIdentity: function()
    {
        $isLoggedIn = this.do.some.ajax.call();
        return $isLoggedIn;
    }
};

I was maybe thinking more of a sort of OOP approach, something like constructing the $cms object by writing it from within PHP:

<script type="text/javascript">
  $cms = new $cms( <?php echo $loggedIn ? 'true', 'false' ?> );
</script>

Now, I believe I can’t use the new keyword like that in Javascript, but I hope you catch my drift, and see where I want to go with this.

  • 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-05-13T19:51:43+00:00Added an answer on May 13, 2026 at 7:51 pm

    You could also do:

    $cms.isLoggedIn = <?php echo $loggedIn ? 'true', 'false' ?>;
    

    That because your $cms object is not a constructor function. If it were, you would have been able to new it.

    var CMS = function (loggedIn) {
        this.loggedIn = loggedIn;
    };
    
    CMS.prototype.hasIdentity = function () {
        return this.loggedIn;
    };
    
    $cms = new CMS(<?php echo $loggedIn ? 'true', 'false' ?>);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CMS system that stores data across tables like this: Entries Table
I have CMS with a script that is executed for each file that is
We have a CMS system that we're currently taking the admin back end and
I have a CMS application that manages multiple websites, today whenever i change the
i have a simple cms on ROR 3.2. with this folder scheme: app |controllers
I have a CMS that multiple people administer. We enable/disable some of our shipping
We have custom cms that currently sits on a vendor's subdomain, such as cms.vendor.com.
I'm building a CMS for a site with php. I have multiple forms on
I worked on a CMS and I want to have diffrent Buttons for special
EPiServer CMS 6 site that suddenly got this error in edit mode. Found alot

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.