Crafty.clone()
public Object .clone(Object obj)
- obj
一个对象
深度克隆 (a.k.a clone)一个对象。
注意: 此函数应用于没有循环引用的普通对象。克隆实体使用实体的.clone
方法代替。
例子
// 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