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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:00:54+00:00 2026-05-26T03:00:54+00:00

I’m currently working on a JavaScript project that’s a little larger than what I’m

  • 0

I’m currently working on a JavaScript project that’s a little larger than what I’m used to. In the past I’ve made the odd carousel and basic visual things.

This time round I’m working on a project that’s more or less making a file management solution in the browser.

My first bit of code is to allow users to select single and multiple files using keyboard commands (arrows and shift) and mouse (click and shift click)

I’ve used a design pattern that I’ve learnt observing colleagues code on another project but I’m unhappy with the amount of code required to call functions and global (to the object) variables, for instance:

SW.selection.addItemsToSelection($(this))

or

SW.selection.vars.$selectedItems

You can see the full code on JSFiddle here

My questions are:

(a) Is there a better structure I could use to organise this code more efficiently.

and

(b) I only have the vaguest understanding of OOP as I struggle to apply it to real world problems – how would this code best be structured following the OOP methodology given its a fragment of what will be a large JS application.

I hope these aren’t too vague! This is something I really struggle to understand but I’d like to improve my JavaScript a lot so taking the rare step of posting here.

  • 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-26T03:00:55+00:00Added an answer on May 26, 2026 at 3:00 am

    You can replace SW.selection with this in most places, if you are in the object scope.

    The design pattern looks like a “singleton” (or it’s equivalent in JavaScript: Object), so there is no need for fancy OOP stuff like inheritance etc. One thing you might consider is the possibility to have private vars in your singleton:

    SW.selection = (function() {
        var private = 'I’m private';
        return {
            public: function() {
                return private;
            }
        }
    }());
    
    SW.selection.public(); // returns 'I’m private', 
                           // but the private variable is not accessible from here
    

    This way, you can store the vars in the private scope so you don’t need to access them via the entire singleton each time using SW.selection.vars.myvar etc.

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

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into
I need a function that will clean a strings' special characters. I do NOT

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.