cocos2d/cocos2d-html5 — pull request #1015 by kennyluck (2013-07-19 02:25:26+00:00)
Title: Optimize John Resig's inheritance pattern (cc.Class.extend) with advanced property initialization.

*This patch is accompanied by a set of demo showcases.*

The idea behind this optimization is "stabilizing memory layout of an instance" and so inline caches can be reduced to minimum size. This is best demonstrated by **B1/B2** of the showcases.

This approach has certain advantages over patching the `this.ctor` method of certain performance-sensitive classes:

- This optimizes all classes derived from `cc.Class`.
- Duplicating codes (initial values on the prototype) is usually a bad idea.
- Patching `this.ctor` would not avoid V8's [77-property-issue](https://github.com/oupengsoftware/v8/wiki/Dictionary-mode#wiki-append-property) - when an instance created by a constructor JS function with no property assignment has more than 76 properties, it turns into "dictionary mode" in V8. See **A1/A2**. **We now build constructor JS functions with property assignments inside.**

The caveat with this patch is obvious - an object now uses *a lot* more memory. I doubt this is a serious issue (`cc.p`, `cc.Point` and `cc.Rect` seem to be more of a memory problem like I pointed out), but if it turns out that it is, we can add a config switch.

Testing results will come later, but feel free to play with this.