问题
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:
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);
})();
来源:https://stackoverflow.com/questions/14892827/how-to-extend-kineticjs-shape