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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:54:36+00:00 2026-05-30T16:54:36+00:00

I have a constructor function which can be used to instantiate a new Button

  • 0

I have a constructor function which can be used to instantiate a new Button object. When creating this object you can suffice the function with one argument. If this argument is an associative array, all the values of the array become properties of the Button object.

So what I’m trying to do is this

function Button(args){
    for (arg in args)
    {
       //Add the name of arg as property of Button with arg as value.
    }
};

var button = new Button({
                     name:"My button",
                     value:"My super special value",
                     color:"black",
                     enabled:false
             });

What this should do is create a button object like this.

button.name      //should be "My button"
button.value     //should be "My super special value",
button.color     //should be "black",
button.enabled   //should be false

I can’t seem to figure out how to accomplish this, because if you get the association it is a string. And this.arg = args[arg] obviously won’t work.

NOTE: the input must be an array, and if a user would put an total other associative array in as argument the properties will be different. {test:true} would dynamicaly create a button with a test property with the value true.

This means button.test = true is not an option. It must be dynamic.

  • 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-30T16:54:37+00:00Added an answer on May 30, 2026 at 4:54 pm

    And this.arg = args[arg] obviously won’t work

    this[arg] = args[arg]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below prog Object.prototype.inherit = function(baseConstructor) { this.prototype = (baseConstructor.prototype); this.prototype.constructor =
I have two constructor : function clsUsagerEmailUserName($nickName, $email) { $this->nickName = $nickName; $this->email =
I have this code: dojo.declare(City, null, { constructor : function(cityid, cityinfo){ } }); dojo.declare(TPolyline,
My program uses a NetworkOutput object which can be used to write data to
I have the following function which constructs one or more y-axes for a Highcharts
I have a constructor like as follows: public Agent(){ this.name = John; this.id =
I have a constructor signature like this public NavigationLink(Func<String> getName, Func<UrlHelper, String> getURL, Func<bool>
hello everyone I'm trying to write function which can unfold int in the list
Currently I have the function CreateLog() for creating a a log4net Log with name
Lets say I have a function which takes a function pointer as a parameter,

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.