简体   繁体   中英

Adding properties to a existing object

thsi is not a jquery ui question but a JavaScript object question

function uiDialog()
{    
   ...............
   ...............

    $('#dialog ').dialog({
        width:'auto',
        height :'auto',
        resizable: false 
    });
    ..............
    ..............
}

Above is a jquery ui dialog code. Now everywhere i want a dialog am calling uiDialog(). Now ui has so many options that are rarely required. So i am considering passing a object as a parameter and appending it to this default data but how can i do it .can i do

$('#dialog ').dialog({
    width:'auto',
    height :'auto',
    resizable: false,
    myObject 
});

Will this work or can you suggest any other way if this fails

Use the jQuery.extend(); function .

$('#dialog ').dialog(
  $.extend(
    {
      width:'auto',
      height :'auto',
      resizable: false
    },
    myObject 
  )
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM