Monday, March 23, 2015

Pass a object by value - assigning / copying object

JSON method:

var myObjDefault = JSON.stringify({
  price: {min: 0, max: 999},
  weight: {min: 0, max: 999},
});

var myObj = JSON.parse(myObjDefault);

Jquery Method:

// Shaw Copy
var oShallowCopy = jQuery.extend({}, o);

// Deep Copy
var oDeepCopy    = jQuery.extend(true, {}, o); 

Reference:

http://stackoverflow.com/questions/7574054/javascript-how-to-pass-object-by-value

No comments: