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.

2
  • 2
    $.extend is your friend here Commented May 11, 2011 at 22:15
  • In this case, better = a solution that does not use $.extend that a a comment author feels is superior in their opinion. Commented May 11, 2011 at 22:53

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Good suggestion- it's also very powerful. I ended up using this after reading more about it.
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));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.