var SingleFactory = function() {
function Operation() {
this.A = 0;
this.B = 0;
}
OperationAdd.prototype = new Operation();
OperationSub.prototype = new Operation();
function OperationAdd() {
this.getResult = function() {
return this.A + this.B;
}
}
function OperationSub() {
this.getResult = function() {
return this.A - this.B;
}
}
function OperationFactory(arg) {
var ret = null;
switch (arg) {
case '+':
ret = new OperationAdd();
break;
case '-':
ret = new OperationSub();
break;
default:
alert(arg);
break;
}
return ret;
}
var a = new OperationFactory('+');
a.A = 10;
a.B = 20;
alert(a.getResult());
}