1

I want to make multiple dialogs and with a default object for most common configuration. Can a configuration object be added in? I tried and this code fails:

var full_dialog = {
    width: "200px",
    height: "300px",
    position: [0,100]
}

$('<div></div>').dialog({
    title: 'Claim# '+ref_num,
    full_dialog
});

I've used $.extend to concatenate objects, I just wondered if there was a better way.

kapa
  • 75,446
  • 20
  • 155
  • 173
Brandon Minton
  • 964
  • 3
  • 13
  • 25

2 Answers2

2

Just use $.extend, it's simple and clear.

Håvard S
  • 22,173
  • 6
  • 59
  • 70
2

If you want to dynamically merge two objects' properties, have a look at this thread's accepted answer: How can I merge properties of two JavaScript objects dynamically?

Then you can do:

var full_dialog = {
    width: "200px",
    height: "300px",
    position: [0,100]
}

$('<div></div>').dialog(merge_options({
    title: 'Claim# '+ref_num
},full_dialog));
Community
  • 1
  • 1
DarthJDG
  • 16,331
  • 11
  • 48
  • 55