cocos2d/cocos2d-html5 — pull request #1016 by kennyluck (2013-07-19 02:53:12+00:00)
Title: Optimize cc.clone by making sure the cloned object has the same prototype chain as the original.

*This patch is accompanied by a two demo showcases.*

This patch was originally part of the [property initialization patch](https://github.com/cocos2d/cocos2d-html5/pull/1015), but it turns out that this is somewhat independent. However, this patch depends on that patch for the performance benefits.

The patched `cc.clone` would now create a "good" clone of the original:

- The cloned object is now of the type of the original's type. For example, a cloned `cc.Sprite` can now be added as a child of `cc.SpriteBatchNode` while previously an assertion fails.
- The cloned object is enough similar to the original such that it doesn't create performance nightmare because of inline cache growth. See **C1/C2** of the showcases.

I'll let you guys decide whether you want to use this instead of customized cloning functions for `cc.Action`s .

We might want to play with other cloning implementation with my **C1/C2**, such as [dankogai's](https://github.com/dankogai/js-object-clone/blob/master/object-clone.js), although I find it hard to believe that it would be more performant as it has the problem I describe in inline comments. I'll get you updated if I manage to get `Object.clone` standardized :)