How to extend KineticJS shape

2019-02-19 14:49发布

For KineticJS version 4.0.0 or less a shape extended a class and could be extended by

var MyCircle = Kinetic.Circle.extend({
    init : function(config) {
        this._super(config));
    },
    myFunc : function(){}
});

Or

Kinetic.MyCircle = function (config) {
    Kinetic.Circle.apply(this, [config]);
};
Kinetic.MyCircle .prototype = {
    myFunc: function () {}
};
Kinetic.GlobalObject.extend(Kinetic.MyCircle , Kinetic.Circle);

In version 4.0.1 they removed the dependencies to the class utility and implemented a custom solution that is supposed to be much faster.

How does one extend a shape with the new solution?

1条回答
Fickle 薄情
2楼-- · 2019-02-19 14:54

Kinetic.GlobalObject became Kinetic.Global (>4.0.1), then
Kinetic.Global is now Kinetic.Util (2013 versions), here is a solution:

(function() {
    Kinetic.MyCircle = function(config) {
        this._initMyCircle(config);
    };

    Kinetic.MyCircle.prototype = {
        _initMyCircle: function(config) {
            Kinetic.Circle.call(this, config);
            },
        myFunc : function(){
        }
    };

  Kinetic.Util.extend(Kinetic.MyCircle, Kinetic.Circle);
})();
查看更多
登录 后发表回答