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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:05:41+00:00 2026-06-09T13:05:41+00:00

I am creating a custom object to be used in some internal applications where

  • 0

I am creating a custom object to be used in some internal applications where I work. I researched some ways to go about doing this – and this is what I came out with.

function ISGrader(text)
{
this.text = text;

this.printInfo = function(){
    alert("Object working " + text);    
}

this.putGrade = function(score)
{
           alert(score);
}
 }

I believe this shows constructor-type functionality, as well as some simple starter methods that I will build on.

Is the above good practice or is there another way that is more standard?

  • 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-09T13:05:43+00:00Added an answer on June 9, 2026 at 1:05 pm

    I prefer a pattern similar to the one below. You can think of it as a 4-step approach:

    (function(parent) {
    
    // 1. Declare private variables and functions that will be
    // accessible by everybody within the scope of this 
    // function, but not outside of it.
    var doSomethingAwesome = function() { .. }; // private function
    var coolInteger = 42; // private variable
    
    // 2. Create the constructor function
    function ISGrader() {
        ..
    }
    
    // 3. Create shared public methods on the prototype object.
    // These will be created only once, and shared between all objects
    // which is more efficient that re-creating each method for each object.
    ISGrader.prototype.printInfo = function() { .. };
    ISGrader.prototype.putGrade = function(score) { .. };
    
    // 4. Expose the constructor to the outside world.
    parent.ISGrader = ISGrader;
    
    })(window);
    

    The reason why everything is enclosed inside a self-executing anonymous function is to ensure the private variables we create inside don’t leak outside to the enclosing scope, and to basically keep things clean.

    Another benefit of declaring the constructor like this is that you can change the parent object easily from say window to a further namespaced object by changing a single word.

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

Sidebar

Related Questions

hello creating a custom object may be a widely published topic, but my lack
I need a help about creating custom wpf controls.I want to create a template
I am creating a custom .net hardware framework that will be used by other
I have created a custom queue where I am doing some processing and thereby
I'm starting to learn about MVC-based applications being that I'm getting into some heavier
I have a couple of queries out here before I start creating my custom
I am creating a custom text box control to have some default formatting and
I'm creating custom UserControl in ASP.NET and I'm using System.ComponentModel.Attributes to decorate properties with
I'm often creating custom assertion methods for my JUnit tests. eg: public void assertArrays(String[]
I'm creating custom forum software for a site I'm building, which includes 2 tables

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.