Search code examples
jqueryextend

Using the $.extend plugin for jQuery on an undeclared variable


This page says to use:

var object = $.extend({}, object1, object2);

But I prefer to scope everything. So if I had a local scope explicitly declared, could I use:

var local = {};
$.extend(local.object, object1, object2);

instead of saying this:

var local = {};
local.object = $.extend({}, object1, object2);

Solution

  • Have you ever tried this approach?

    var local = { object: {} }; 
    $.extend(local.object, object1, object2);
    

    btw, I didn't see problem with the third approach.