Crafty.clone()

public Object .clone(Object obj)
obj

an object

Deep copy (a.k.a clone) of an object.

Note: This function should be used for plain objects with no cyclic references. To clone an entity use its .clone method instead.

Example

// Null or Primitive types
Crafty.clone(null); // returns null
Crafty.clone(4);    // returns 4

// Objects
var globalCount = 0;
var obj1 = {
  count: 0,
  inc: function(){
     this.count++;
     globalCount++;
  },
  log: function(){
    console.log(this.count + '/' + globalCount);
  }
};

obj1.inc();
obj1.log(); // prints "1/1" to the log

var obj2 = Crafty.clone(obj1);
obj2.log(); // prints "1/1" to the log

obj1.inc();
obj1.log(); // prints "2/2" to the log
obj2.log(); // prints "1/2" to the log