关于Node的removeAllChildren

Node的removeAllChildren会调用每个child的destroy吗?如果没有,如何让它有?

不会,要调用 destroy 唯一的办法是每个 child 分别 destroy 一次。

    removeAllChildren: function (cleanup) {
        // not using detachChild improves speed here
        var children = this._children;
        if (cleanup === undefined)
            cleanup = true;
        for (var i = children.length - 1; i >= 0; i--) {
            var node = children[i];
            if (node) {
                // If you don't do cleanup, the node's actions will not get removed and the
                if (cleanup)
                    node.cleanup();
                node.parent = null;
            }
        }
        this._children.length = 0;
    },

removeAllChildren 的实现非常简单,你自己包装一个会遍历 destroy 的类似方法就是了

1赞