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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:55:33+00:00 2026-06-14T02:55:33+00:00

A Little Background… I have an an object called SineMacula which houses many methods

  • 0

A Little Background…

I have an an object called SineMacula which houses many methods for creating form elements and making these form elements do things on a page.

Firstly, when the page loads, a method called setFields() is called which loops through all the fields on a page and sets them appropriately i.e. autocomplete, checkbox etc…

The code for setFields() looks like this:

/**
 * Set Fields
 * This function will set all fields
 *
 * The options:
 * - fields: the fields selector to loop through
 *
 * @param object options The field options
 */
SineMacula.prototype.setFields = function (options){
    // Set the defaults for the fields
    var options = $.extend({
        fields: '.field', // Define the default field selector
    },options);
    // Loop through the fields and set the events
    $(options.fields).each(function(){
        // Set the field events
        SineMacula.setBlur($(this));        
        SineMacula.setFocus($(this));
        SineMacula.setToggleLabel($(this));
        // If the field is a checkbox then set it
        if($(this).parent().hasClass('checkbox')){
            SineMacula.setCheckbox($(this).parent());
        }
        // If the field is an autocomplete then set it
        if($(this).parent().hasClass('autocomplete')){
            SineMacula.setDropdown($(this).parent(),{source:$(this).attr('data-source')});
        }
        // etc...
    });
};

Most of the code above can be ignored, but I have inserted all of it so that you can see exactly what I am doing.

My Question

I have quite a few methods of the SineMacula object such as setCheckbox(), setDropdown()…

What I would like to know is, should I be treating these methods as objects in themselves?

So should my code look like this instead:

if($(this).parent().hasClass('autocomplete')){
     new SineMacula.dropdown($(this).parent(),{source:$(this).attr('data-source')});
}

Notice the new keyword before calling the dropdown() method.

Is this a better method of working things? Will be use less memory etc?

  • 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-14T02:55:34+00:00Added an answer on June 14, 2026 at 2:55 am

    There is no reason to create an instance of an object only to call the constructor and then throw the object away. By doing the work in the constructor you are just using it as a regular function, but with the overhead of creating an unused object.

    (In fact you don’t seem to use the SineMacula instance for anything either, other than as a namespace for the methods.)

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

Sidebar

Related Questions

A little background information: I have a table called table_a , which has 12
Little Background: I have csv file which has lots of rows and each row
A little background: I have a perl script which is performing a number of
little background: currently putting together a website that is selling products, many of which
Little background: I have a JTextField called reading. It is located on a JFrame
A little background: I am loading a WPF UI from a database which is
First a little background: I have already managed to connect to a Microsoft SOAP
Little background, the table view is filled by a fetchedResultsController which fills the table
A little background: My app is designed as a web form in a UITableView.
A little background so you understand what I'm trying to do. I am making

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.