我有这种基本类型:
function Transition(slide, settings){
this.slide = slide;
this.settings = settings;
this.duration = (this.settings['transitionSpeed'] / 1000) + 's'
}
我有这样的派生类型:
function FadeTransition(){
Transition.call(this);
}
FadeTransition.prototype = new Transition();
FadeTransition.prototype.constructor = FadeTransition;
我有一个工厂对象,我想创建各种派生类型:
var TransitionFactory = function () {
return {
createTransition: function (transitionType, slide, settings) {
if (transitionType) {
type = transitionType;
}
if (type == 'fade') {
return new FadeTransition(slide, settings);
};
},
//Set default transition
type: "fade"
};
};
我想通过这样做来实例化我的各种派生转换:
var outTransition = this.transitionFactory.createTransition(currentSlide, currentSlide.outTransition, this.settings);
但是,我没有那么做,因为我的FadeTransition定义中的这一行:
FadeTransition.prototype = new Transition();
我收到错误,因为Transition
构造函数需要参数,但是当我将其构造函数分配给FadeTransition.prototype
时,我没有传入任何内容。我应该以某种方式吗?
利用工厂的最佳方法是什么,并且能够用它创建派生对象?