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
  • 77,694
  • 21
  • 158
  • 175
Brandon Minton
  • 994
  • 3
  • 13
  • 25

2 Answers2

2

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

Håvard S
  • 23,244
  • 8
  • 61
  • 72
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,511
  • 11
  • 49
  • 56