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

  • Home
  • SEARCH
  • 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 9185853
In Process

The Archive Base Latest Questions

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

I am trying to simulate a namespace feature in Javascript. var com = {};

  • 0

I am trying to simulate a namespace feature in Javascript.

var com                   = {};
com.domain                = {};
com.domain.system         = {};
com.domain.net            = {};
com.domain.net.ip         = {};
com.domain.net.ip.tcp     = {};
com.domain.net.ip.udp     = {};
com.domain.net.ip.ssl     = {};
com.domain.util           = {};
com.domain.util.timer     = {};
com.domain.plugins        = {};
com.domain.session        = {};
com.domain.io             = {};
com.domain.algorithm      = {};
com.domain.debug          = {};

This is the namespaces declaration. Later I will add functions to these namespaces.

This is my selector function:

For a convenient way to use namespaces, I add a function named $. This function will walk all namespaces in com. If the selected name exists, return the object.

function $ (selector) {
  function digger (namespace, selector) {
    for (var prop in namespace) {
      if (typeof namespace[prop] == "array" || typeof namespace[prop] == "object") {
        if (prop == selector) {
          return namespace[prop];
        }
        var dig = digger(namespace[prop], selector);
        if (dig != null) {
          return dig;
        }
      } else {
        if (prop == selector) {
          return namespace[prop];
        }
      }
    }
  }
  return digger (com, selector);
}

After that, I add a timer to namespace com.doamin.util.

com.domain.util.timer = function () {
    this._handle = new InnerObj.SystemTimer(io);
    return this;
};

com.domain.util.timer.prototype.expiresFromNow = function (seconds, cbHandler) { 
    this._handle.ExpiresFromNow (seconds, cbHandler);
};

com.domain.util.timer.prototype.wait = function (seconds, cbHandler) { 
    this._handle.Wait (seconds, cbHandler);
};

com.domain.util.timer.prototype.expiresAt = function (seconds, cbHandler) { 
    this._handle.Wait (seconds, cbHandler);
};

com.domain.util.timer.prototype.cancel = function () {
    this._handle.Cancel ();    
};

Usage:

 1. var timer = new com.domain.util.timer ();            OK
    timer.expiresAt (1, {});                             OK
 2. var func = $("timer");                               OK 
    var timer =  new func ();                            OK 
    timer.expiresAt (1, {});                             OK

But but but but but

var timer = new $("timer") ();                           NG

Can anyone tell me why the last new function is not working?

  • 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-17T19:22:45+00:00Added an answer on June 17, 2026 at 7:22 pm

    Try var timer = new ($("timer"))();.

    Your question is not clear but I guess since $("timer") returns a function, you want a new instance of the result of $("timer") and not a new instance of $().

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

Sidebar

Related Questions

I am trying to simulate asymmetric key system. I use following code to generate
I'm trying to simulate an actual tab key press in JavaScript. I don't want
I am trying to simulate a problem we have with a particular domain ID
I'm trying to simulate the InstallURL property of a VS.net install MSI... I've got
I'm trying to simulate behavior of os.system with Popen and waitpid on Ubuntu and
I am trying to simulate a form submission on an ASPX.NET site. The flow
I am trying to simulate a production system and now I am having trouble
I'm trying to simulate a particle system using OpenGl but I can't get it
I am trying to simulate an accordion menu in CSS. I cannot use javascript
I am trying to simulate a foreign key behaviour using JSON.Net but I can't

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.