2
\$\begingroup\$

I'm trying to create a menu for widgets with editable settings. As of now I'm setting these settings per object by coding them in like you can see below.

How could I make this shorter / programmatically create those objects with settings (settings are stored in a MySQL database)?

    var widgetArray = new Array();
var objectArray = {
    jira_users: function(){
        this.StartUID = 1;
        this.length = 4;
    },
    calls_per_day: function(){
        this.length = 5;
    },
    calls_per_week: function(){
        this.length = 5;
    },
    calls_per_week_day: function(){
        this.length = 5;
    },
    check_servers: function(){
        this.length = 4;
    }
}

objectArray.jira_users.prototype = {
    constructor: objectArray.jira_users,
    UpdateStartUID: function(newid){
        this.StartUID = newid;
    },
    Update: function($form){
        this.UpdateStartUID($form.find("#user_id_input").val());
    }
}

objectArray.calls_per_day.prototype = {
    constructor: objectArray.calls_per_day,
    UpdateLength: function(newLength){
        this.length = newLength;
    },
    Update: function($form){
        this.UpdateLength($form.find("#display_length").val());
    }
}

objectArray.calls_per_week.prototype = {
    constructor: objectArray.calls_per_week,
    UpdateLength: function(newLength){
        this.length = newLength;
    },
    Update: function($form){
        this.UpdateLength($form.find("#display_length").val());
    }
}

objectArray.calls_per_week_day.prototype = {
    constructor: objectArray.calls_per_week_day,
    UpdateLength: function(newLength){
        this.length = newLength;
    },
    Update: function($form){
        this.UpdateLength($form.find("#display_length").val());
    }
}
\$\endgroup\$
  • \$\begingroup\$ To make life easier for reviewers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. See also this meta question \$\endgroup\$ – Simon Forsberg Sep 9 '14 at 8:41
  • \$\begingroup\$ @SimonAndréForsberg sorry, I've added a little context. \$\endgroup\$ – Stijn Bernards Sep 9 '14 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.