SO - cloning a class instance

http://stackoverflow.com/questions/8445776/javascript-cloning-a-class-instance

JavaScript

function test(element) {
  $(docment).write("testing plain object: " + $.isPlainObject(element));

  // create and array of elements and clone [0] to [1]
  var states = [{ elements: [element] }];
  states.push($.extend(true, {}, states[0]))

  // modify one element
  states[1].elements[0].changes = { am: 12 };
    
  // see if states[0] and states[1] both changed 
  console.log(states[0].elements[0], states[1].elements[0]);
}

// ========================================
// 1) test an object created by constructor
// ========================================
function Element() {
    this.changes = {};
}
test(new Element());

// ========================================
// 2) test a plain object
// ========================================
test({ changes: {} });