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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:21:44+00:00 2026-05-31T13:21:44+00:00

I am creating a small project that heavily relies on JavaScript. I come from

  • 0

I am creating a small project that heavily relies on JavaScript. I come from php/mysql and now stepping into node.js/javascript/mongodb, and I hve to say it’s quite a mindswitch.

I want to create a simple object that has some special function that I can use in the page. I have been looking at some tutorial, and looking at the libraries such as jquery and backbone, but I need some final advice on my decision.

I only need some small functions, and no cross-browser support, that’s why I don’t choose something like backbone. Maybe ill change to that later when I have a better crasp on JavaScript programming.

What is confusing me is whether to use the new, or maybe wrapping the code into a self-invoking function.

I see jquery creates an object inside the window and than exposes that, but I have no idea how that works.

Enough intro, now to the point. I have created something like this:

var $s = Object.create({

    page: Object.create({

        title: 'pagetitle',
        html: '',
        data: {},

        render: function(){
            // Basic render function
        }

    }),

    socket: Object.create({
        // My websocket connection
    }),

    store: function(key, value) {
        localStorage.setItem(key, JSON.stringify(value));
    },

    retrieve: function(key) {
        var value = localStorage.getItem(key);
        return value && JSON.parse(value);
    },

    slugify: function(slug){
        return slug.replace(/[^a-zA-Z 0-9-]+/g,'').toLowerCase().replace(/ /g,'-');
    }

});

This are just a few random functions I put in.

I haven’t tested this yet, it is a draft, I want to know if this is any good.

Now I was thinking i can do some stuff like this:

$s.page.html = 'somehtml';
$s.page.render();

// Maybe
$s.store( $s.page.title, $s.page.html );

I do use jQuery and jQuery templating, so something like this could be possible:

$.tmpl( $s.page.html, $s.page.data ).appendTo( "#content" );
  • 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-31T13:21:45+00:00Added an answer on May 31, 2026 at 1:21 pm

    Nothing fancy is needed here. You can create a global javascript object with a method like this:

    var myGlobalObject = {};
    myGlobalObject.testFunction = function() {
        // put your code here
    };
    

    You can then call that like this:

    myGlobalObject.testFunction();
    

    One slightly more flexible design pattern you will often seen used is this:

    var myGlobalObject = myGlobalObject || {};
    
    myGlobalObject.testFunction = function() {
        // put your code here
    };
    

    This is used when there might be lots of different pieces of code contributing to myGlobalObject and they all want to make sure that it’s properly declared before adding properties to it. This way of doing it, creates it if it doesn’t already exist and if it does already exist, leaves the methods and properties on it that might already be there. This allows multiple modules to each contribute initialization to myGlobalObject without regards for the order they load.

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

Sidebar

Related Questions

I am creating a small commercial web project running Apache/WSGI/Django/MySQL. I have a development
I am creating a WinForm project that displays messages from a server and a
So I'm working on a small project that involved creating a camera class with
So I was creating a small project for fun last night that involves creating
I am currently creating a class for a small project and ran into an
I'm creating a small tool that will fetch new issues from our redmine repository
I am creating a small project on ASP.NET. I want a simple drop down
I am creating a basic screensaver for a small project for college and I
Rails newbie here struggling with a small project. I am creating a simple ship
I'm creating a small framework for my web projects in PHP so I don'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.