function extend(a, b) { for (var k in b) a[k] = b[k]; return a; } var defaultOpt = { url: '', type: 'GET' }; (function(newOpt) { newOpt = extend(extend({}, defaultOpt), newOpt || {}); console.log(newOpt); })({url: 'new'});