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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:19:45+00:00 2026-06-04T16:19:45+00:00

In my company we have a survey framework to help stakeholders create surveys, I’m

  • 0

In my company we have a survey framework to help stakeholders create surveys, I’m trying to create a re-usable object which will allow a team member to easily set the width of a particular question for a survey – they can sometimes be a bit squished depending on the length of the answers. I’m trying to use a combination of the module and constructor pattern but not sure if I pulled it off correctly. Is there a better way to write my code?

        var WidthIncreaser = (function(){
            return function (element, words, width) {

                var element = $(element);
                var re = new RegExp(words, 'gi');

                return {
                    init: function() {
                        if (element.text().match(re)) {
                            element.width(width);
                        }
                    }
                };
            };
        })();

        var tr = new WidthIncreaser('td.choicev-question:first', 'Applicable from the', 400);
        tr.init();

The idea is, somebody can create a new instance of WidthIncreaser and pass in an element, a string which matches the question’s text so it’s the right question being targeted and the size to set width of the question to.

Thanks for the advice in advance!

  • 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-04T16:19:46+00:00Added an answer on June 4, 2026 at 4:19 pm

    You are double wrapping stuff. Anyways, the common module pattern I see is just a function that returns an object with closure.

    No need for the new keyword nor an immediate function. Immediate functions are usually used when only one object is made and assigned directly to one variable. In your case, you wanted to make “instances”.

    var WidthIncreaser = function(element, words, width) {
    
        var element = $(element),
            re = new RegExp(words, 'gi');
    
        return {
            init: function() {
                if (element.text().match(re)) {
                    element.width(width);
                }
            }
        };
    };
    
    var tr = WidthIncreaser('td.choicev-question:first', 'Applicable from the', 400);
    
    tr.init();​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a survey system for my company and I have it setup
Most of the software company have old software which continue maintain, and they also
In our company we have staging and production servers. I'm trying to have them
I have an company asp.net website with textboxes which may contain several hundred words.
I have Company object and @OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }, mappedBy
I have company, customer, supplier etc tables which all have address information related columns.
Our company have a need to set up some solution, that would allow us
My company have just baught Ivan's CheckItOut extension , and I'm trying to add
I'm working on an old web application my company uses to create surveys. I
In our company we have discussion going on whether to allow xml/xsd strucutures (used

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.