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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:00:01+00:00 2026-06-09T04:00:01+00:00

If I created a javascript object like so: Test = function(params) { this.test =

  • 0

If I created a javascript object like so:

Test = function(params) {
    this.test = params.test || 'element';
    this.test1 = params.test1 || '#000';
    this.test2 = params.test2;
    this.test3 = params.test3;

    //need a neat little initialise function to create some html elements here! 
}

var test = new Test({test: "#CCC", test1: [0, 1, 3], test2: [0, 1, 3]});

How would I then create a proper initialise function that would run when an instance of that object was created like above.

Would I simple make a function and then call it, or is there a way to make a function that runs on its own when an object instance is created.

  • 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-09T04:00:02+00:00Added an answer on June 9, 2026 at 4:00 am

    Your constructor already is a function, you can just place the code there. Technically speaking, the constructor is the initialisation function for objects.

    Would I simple make a function and then call it, or is there a way to make a function that runs on its own when an object instance is created.

    That depends. Can you reuse the html element creation code somewhere else than in the constructor? Then put it in a separate function (possibly on the prototype) and call that from the constructor.

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

Sidebar

Related Questions

I have a Javascript object created as follows: var ccStatTracker = (function (){ ccmap:{
In JavaScript, I've created an object like so: var data = { 'PropertyA': 1,
I'd like to be able to create a javascript object from my html form
In javascript you can create a Date object from a string, like var mydate
I've created a Javascript object via prototyping. I'm trying to render a table dynamically.
I've created a JavaScript object to hold onto a value set by a user
Is it bad javascript practice to not assign a newly created object to a
i got a question when create a javascript object, when one function invoking another
I'd like to have JavaScript objects within another JavaScript object as such: Issues: -
I need to deserialize some JavaScript object represented in JSON to an appropriate C#

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.