如何正确引用ES6类中的内联函数?

时间:2015-09-23 12:05:11

标签: javascript ecmascript-6 paperjs

所以我试图使用paper.js在画布上设置一些项目的动画。目前我有这个(有些项目是为了简洁而删除):

class Sprite {
    constructor() {
        animate();
    }
    animate() {
        paper.view.attach('frame', function (event) {
            if (event.count < destinationX * tileWidth) {
                //animate stuff
            } else {
                //exit here
                paper.view.detach('frame', this);
            }
        });
    }
}

问题是动画最终开始,但实际上从未停止过。我也试过

animate() {
        paper.view.attach('frame', doAnimation);
        function doAnimation(event){
            if (event.count < destinationX * tileWidth) {
                //animate stuff
            } else {
                //exit here
                paper.view.detach('frame', doAnimation);
            }
        }
    }

但是这实际上从未导致动画附加到视图,它永远不会启动。我应该使用什么语法来使所有内容正确链接?

0 个答案:

没有答案
相关问题